diff options
author | Nikias Bassen | 2019-01-21 01:03:44 +0100 |
---|---|---|
committer | Nikias Bassen | 2019-01-21 01:11:06 +0100 |
commit | 5f8ca6e30334b81bd39a67f87a011cee8f282c3c (patch) | |
tree | 9ebaa5e3f37a43da60da335b5b7972446301c4b0 /src | |
parent | e1f852150d5d3794f32c0ee0fc8314dcb7d2f499 (diff) | |
download | libplist-5f8ca6e30334b81bd39a67f87a011cee8f282c3c.tar.gz libplist-5f8ca6e30334b81bd39a67f87a011cee8f282c3c.tar.bz2 |
xplist: Fix dtostr() inserting ':' to output string when fractional part overflows
Diffstat (limited to 'src')
-rw-r--r-- | src/xplist.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/xplist.c b/src/xplist.c index c89b143..fc8fd61 100644 --- a/src/xplist.c +++ b/src/xplist.c @@ -107,9 +107,22 @@ static size_t dtostr(char *buf, size_t bufsize, double realval) int64_t v; size_t len; size_t p; + double CORR = 0.0000005; f = modf(f, &ip); - len = snprintf(buf, bufsize, "%s%"PRIi64, ((f < 0) && (ip >= 0)) ? "-" : "", (int64_t)ip); + v = (int64_t)ip; + if (f < 0) { + if (((int)((f - CORR) * -10.0f)) >= 10) { + v--; + f = 0; + } + } else { + if (((int)((f + CORR) * 10.0f)) >= 10) { + v++; + f = 0; + } + } + len = snprintf(buf, bufsize, "%s%"PRIi64, ((f < 0) && (ip >= 0)) ? "-" : "", v); if (len >= bufsize) { return 0; } @@ -117,7 +130,7 @@ static size_t dtostr(char *buf, size_t bufsize, double realval) if (f < 0) { f *= -1; } - f += 0.0000004; + f += CORR; p = len; buf[p++] = '.'; |