summaryrefslogtreecommitdiffstats
path: root/src/xplist.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/xplist.c')
-rw-r--r--src/xplist.c31
1 files changed, 28 insertions, 3 deletions
diff --git a/src/xplist.c b/src/xplist.c
index d953e23..eaa2468 100644
--- a/src/xplist.c
+++ b/src/xplist.c
@@ -184,7 +184,11 @@ static void node_to_xml(node_t* node, void *xml_struct)
184 case PLIST_UINT: 184 case PLIST_UINT:
185 tag = XPLIST_INT; 185 tag = XPLIST_INT;
186 val = (char*)malloc(64); 186 val = (char*)malloc(64);
187 (void)snprintf(val, 64, "%"PRIu64, node_data->intval); 187 if (node_data->length == 16) {
188 (void)snprintf(val, 64, "%"PRIu64, node_data->intval);
189 } else {
190 (void)snprintf(val, 64, "%"PRIi64, node_data->intval);
191 }
188 break; 192 break;
189 193
190 case PLIST_REAL: 194 case PLIST_REAL:
@@ -377,9 +381,30 @@ static void xml_to_node(xmlNodePtr xml_node, plist_t * plist_node)
377 if (!xmlStrcmp(node->name, XPLIST_INT)) 381 if (!xmlStrcmp(node->name, XPLIST_INT))
378 { 382 {
379 xmlChar *strval = xmlNodeGetContent(node); 383 xmlChar *strval = xmlNodeGetContent(node);
380 data->intval = strtoull((char*)strval, NULL, 0); 384 int is_negative = 0;
385 char *str = (char*)strval;
386 if ((str[0] == '-') || (str[0] == '+')) {
387 if (str[0] == '-') {
388 is_negative = 1;
389 }
390 str++;
391 }
392 char* endp = NULL;
393 data->intval = strtoull((char*)str, &endp, 0);
394 if ((endp != NULL) && (strlen(endp) > 0)) {
395 fprintf(stderr, "%s: integer parse error: string contains invalid characters: '%s'\n", __func__, endp);
396 }
397 if (is_negative || (data->intval <= INT64_MAX)) {
398 int64_t v = data->intval;
399 if (is_negative) {
400 v = -v;
401 }
402 data->intval = (uint64_t)v;
403 data->length = 8;
404 } else {
405 data->length = 16;
406 }
381 data->type = PLIST_UINT; 407 data->type = PLIST_UINT;
382 data->length = 8;
383 xmlFree(strval); 408 xmlFree(strval);
384 continue; 409 continue;
385 } 410 }