summaryrefslogtreecommitdiffstats
path: root/src/bplist.c
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2017-01-28 04:47:40 +0100
committerGravatar Nikias Bassen2017-01-28 04:47:40 +0100
commit3131bdd3210b9fa2bfee66c63ce1144bea159823 (patch)
tree07770e4e64229f8c1b63b27f50f4f8ba6788852e /src/bplist.c
parentb937059c4dfb1f966cd835d456e91a625d27cf49 (diff)
downloadlibplist-3131bdd3210b9fa2bfee66c63ce1144bea159823.tar.gz
libplist-3131bdd3210b9fa2bfee66c63ce1144bea159823.tar.bz2
bplist: Improve writing of data, string, and unicode nodes
Diffstat (limited to 'src/bplist.c')
-rw-r--r--src/bplist.c25
1 files changed, 7 insertions, 18 deletions
diff --git a/src/bplist.c b/src/bplist.c
index 94b0793..f1bfcc0 100644
--- a/src/bplist.c
+++ b/src/bplist.c
@@ -884,22 +884,13 @@ static void write_date(bytearray_t * bplist, double val)
static void write_raw_data(bytearray_t * bplist, uint8_t mark, uint8_t * val, uint64_t size)
{
- uint8_t *buff = NULL;
uint8_t marker = mark | (size < 15 ? size : 0xf);
byte_array_append(bplist, &marker, sizeof(uint8_t));
- if (size >= 15)
- {
- bytearray_t *int_buff = byte_array_new();
- write_int(int_buff, size);
- byte_array_append(bplist, int_buff->data, int_buff->len);
- byte_array_free(int_buff);
+ if (size >= 15) {
+ write_int(bplist, size);
}
- //stupid unicode buffer length
- if (BPLIST_UNICODE==mark) size *= 2;
- buff = (uint8_t *) malloc(size);
- memcpy(buff, val, size);
- byte_array_append(bplist, buff, size);
- free(buff);
+ if (BPLIST_UNICODE==mark) size <<= 1;
+ byte_array_append(bplist, val, size);
}
static void write_data(bytearray_t * bplist, uint8_t * val, uint64_t size)
@@ -916,12 +907,10 @@ static void write_string(bytearray_t * bplist, char *val)
static void write_unicode(bytearray_t * bplist, uint16_t * val, uint64_t size)
{
uint64_t i = 0;
- uint64_t size2 = size * sizeof(uint16_t);
- uint8_t *buff = (uint8_t *) malloc(size2);
- memcpy(buff, val, size2);
+ uint16_t *buff = (uint16_t*)malloc(size << 1);
for (i = 0; i < size; i++)
- byte_convert(buff + i * sizeof(uint16_t), sizeof(uint16_t));
- write_raw_data(bplist, BPLIST_UNICODE, buff, size);
+ buff[i] = be16toh(val[i]);
+ write_raw_data(bplist, BPLIST_UNICODE, (uint8_t*)buff, size);
free(buff);
}