summaryrefslogtreecommitdiffstats
path: root/src/bplist.c
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2017-01-28 04:45:35 +0100
committerGravatar Nikias Bassen2017-01-28 04:45:35 +0100
commit962d4064b690af1c479f7676b3e36f08eaa593c6 (patch)
treefe49aaf13ef250651f3de8da20606756d0f805b3 /src/bplist.c
parent458341fcc360db6e0bac0619e2512e6050f4e8c7 (diff)
downloadlibplist-962d4064b690af1c479f7676b3e36f08eaa593c6.tar.gz
libplist-962d4064b690af1c479f7676b3e36f08eaa593c6.tar.bz2
bplist: Improve writing of integer nodes
Diffstat (limited to 'src/bplist.c')
-rw-r--r--src/bplist.c33
1 files changed, 12 insertions, 21 deletions
diff --git a/src/bplist.c b/src/bplist.c
index a2fb9be..ed3c0b9 100644
--- a/src/bplist.c
+++ b/src/bplist.c
@@ -837,36 +837,27 @@ static void serialize_plist(node_t* node, void* data)
837 837
838static void write_int(bytearray_t * bplist, uint64_t val) 838static void write_int(bytearray_t * bplist, uint64_t val)
839{ 839{
840 uint64_t size = get_needed_bytes(val); 840 int size = get_needed_bytes(val);
841 uint8_t *buff = NULL; 841 uint8_t sz;
842 //do not write 3bytes int node 842 //do not write 3bytes int node
843 if (size == 3) 843 if (size == 3)
844 size++; 844 size++;
845 sz = BPLIST_UINT | Log2(size);
845 846
846#ifdef __BIG_ENDIAN__ 847 val = be64toh(val);
847 val = val << ((sizeof(uint64_t) - size) * 8); 848 byte_array_append(bplist, &sz, 1);
848#endif 849 byte_array_append(bplist, (uint8_t*)&val + (8-size), size);
849
850 buff = (uint8_t *) malloc(sizeof(uint8_t) + size);
851 buff[0] = BPLIST_UINT | Log2(size);
852 memcpy(buff + 1, &val, size);
853 byte_convert(buff + 1, size);
854 byte_array_append(bplist, buff, sizeof(uint8_t) + size);
855 free(buff);
856} 850}
857 851
858static void write_uint(bytearray_t * bplist, uint64_t val) 852static void write_uint(bytearray_t * bplist, uint64_t val)
859{ 853{
860 uint64_t size = 16; 854 uint8_t sz = BPLIST_UINT | 4;
861 uint8_t *buff = NULL; 855 uint64_t zero = 0;
862 856
863 buff = (uint8_t *) malloc(sizeof(uint8_t) + size); 857 val = be64toh(val);
864 buff[0] = BPLIST_UINT | 4; 858 byte_array_append(bplist, &sz, 1);
865 memset(buff + 1, '\0', 8); 859 byte_array_append(bplist, &zero, sizeof(uint64_t));
866 memcpy(buff + 9, &val, 8); 860 byte_array_append(bplist, &val, sizeof(uint64_t));
867 byte_convert(buff + 9, 8);
868 byte_array_append(bplist, buff, sizeof(uint8_t) + size);
869 free(buff);
870} 861}
871 862
872static void write_real(bytearray_t * bplist, double val) 863static void write_real(bytearray_t * bplist, double val)