File C0005-Improve-writing-of-UID-nodes.patch of Package libplist.4090

From b937059c4dfb1f966cd835d456e91a625d27cf49 Mon Sep 17 00:00:00 2001
From: Nikias Bassen <nikias@gmx.li>
Date: Sat, 28 Jan 2017 04:46:37 +0100
Subject: [PATCH] bplist: Improve writing of UID nodes

---
 src/bplist.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/src/bplist.c b/src/bplist.c
index ed3c0b9..94b0793 100644
--- a/src/bplist.c
+++ b/src/bplist.c
@@ -1009,22 +1009,16 @@ static void write_dict(bytearray_t * bplist, node_t* node, hashtable_t* ref_tabl
 static void write_uid(bytearray_t * bplist, uint64_t val)
 {
     val = (uint32_t)val;
-    uint64_t size = get_needed_bytes(val);
-    uint8_t *buff = NULL;
+    int size = get_needed_bytes(val);
+    uint8_t sz;
     //do not write 3bytes int node
     if (size == 3)
         size++;
+    sz = BPLIST_UID | (size-1); // yes, this is what Apple does...
 
-#ifdef __BIG_ENDIAN__
-    val = val << ((sizeof(uint64_t) - size) * 8);
-#endif
-
-    buff = (uint8_t *) malloc(sizeof(uint8_t) + size);
-    buff[0] = BPLIST_UID | (size-1); // yes, this is what Apple does...
-    memcpy(buff + 1, &val, size);
-    byte_convert(buff + 1, size);
-    byte_array_append(bplist, buff, sizeof(uint8_t) + size);
-    free(buff);
+    val = be64toh(val);
+    byte_array_append(bplist, &sz, 1);
+    byte_array_append(bplist, (uint8_t*)&val + (8-size), size);
 }
 
 static int is_ascii_string(char* s, int len)
openSUSE Build Service is sponsored by