summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/bplist.c33
1 files changed, 10 insertions, 23 deletions
diff --git a/src/bplist.c b/src/bplist.c
index 5a9d678..0c57a75 100644
--- a/src/bplist.c
+++ b/src/bplist.c
@@ -93,22 +93,6 @@ union plist_uint_ptr
93 }) 93 })
94 94
95 95
96static void byte_convert(uint8_t * address, size_t size)
97{
98#ifdef __LITTLE_ENDIAN__
99 uint8_t i = 0, j = 0;
100 uint8_t tmp = 0;
101
102 for (i = 0; i < (size / 2); i++)
103 {
104 tmp = address[i];
105 j = ((size - 1) + 0) - i;
106 address[i] = address[j];
107 address[j] = tmp;
108 }
109#endif
110}
111
112#ifndef bswap16 96#ifndef bswap16
113#define bswap16(x) ((((x) & 0xFF00) >> 8) | (((x) & 0x00FF) << 8)) 97#define bswap16(x) ((((x) & 0xFF00) >> 8) | (((x) & 0x00FF) << 8))
114#endif 98#endif
@@ -353,19 +337,22 @@ static plist_t parse_unicode_node(const char **bnode, uint64_t size)
353 337
354 data->type = PLIST_STRING; 338 data->type = PLIST_STRING;
355 unicodestr = (uint16_t*) malloc(sizeof(uint16_t) * size); 339 unicodestr = (uint16_t*) malloc(sizeof(uint16_t) * size);
356 memcpy(unicodestr, *bnode, sizeof(uint16_t) * size);
357 for (i = 0; i < size; i++) 340 for (i = 0; i < size; i++)
358 byte_convert((uint8_t *) (unicodestr + i), sizeof(uint16_t)); 341 unicodestr[i] = be16toh(((uint16_t*)*bnode)[i]);
359 342
360 tmpstr = plist_utf16_to_utf8(unicodestr, size, &items_read, &items_written); 343 tmpstr = plist_utf16_to_utf8(unicodestr, size, &items_read, &items_written);
361 free(unicodestr); 344 free(unicodestr);
345 if (!tmpstr) {
346 plist_free_data(data);
347 return NULL;
348 }
349 tmpstr[items_written] = '\0';
362 350
363 data->type = PLIST_STRING; 351 data->type = PLIST_STRING;
364 data->strval = (char *) malloc(sizeof(char) * (items_written + 1)); 352 data->strval = realloc(tmpstr, items_written+1);
365 memcpy(data->strval, tmpstr, items_written); 353 if (!data->strval)
366 data->strval[items_written] = '\0'; 354 data->strval = tmpstr;
367 data->length = strlen(data->strval); 355 data->length = items_written;
368 free(tmpstr);
369 return node_create(NULL, data); 356 return node_create(NULL, data);
370} 357}
371 358