summaryrefslogtreecommitdiffstats
path: root/src/xplist.c
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2021-11-08 03:12:51 +0100
committerGravatar Nikias Bassen2021-11-08 03:12:51 +0100
commita9e34bd29ae9dcdae55bdf5fb8a23c9b1c02eee9 (patch)
treeabe78c18c6f5538980631bb60f7f0f1eb471bcb2 /src/xplist.c
parentcf7a3f3d7c06b197ee71c9f97eb9aa05f26d63b5 (diff)
downloadlibplist-a9e34bd29ae9dcdae55bdf5fb8a23c9b1c02eee9.tar.gz
libplist-a9e34bd29ae9dcdae55bdf5fb8a23c9b1c02eee9.tar.bz2
xplist: Better size estimation for PLIST_REAL nodes
Diffstat (limited to 'src/xplist.c')
-rw-r--r--src/xplist.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/xplist.c b/src/xplist.c
index 263d88e..2eaba55 100644
--- a/src/xplist.c
+++ b/src/xplist.c
@@ -113,7 +113,7 @@ static size_t dtostr(char *buf, size_t bufsize, double realval)
} else {
size_t i = 0;
len = snprintf(buf, bufsize, "%.*g", 17, realval);
- for (i = 0; i < len; i++) {
+ for (i = 0; buf && i < len; i++) {
if (buf[i] == ',') {
buf[i] = '.';
break;
@@ -479,7 +479,7 @@ static void node_estimate_size(node_t *node, uint64_t *size, uint32_t depth)
*size += (XPLIST_INT_LEN << 1) + 6;
break;
case PLIST_REAL:
- *size += num_digits_i((int64_t)data->realval) + 7;
+ *size += dtostr(NULL, 0, data->realval);
*size += (XPLIST_REAL_LEN << 1) + 6;
break;
case PLIST_DATE: