Commit 1b9bf8b0 authored by Nikias Bassen's avatar Nikias Bassen

bplist: Remove unnecessary allocation and unused variables

parent baf50929
...@@ -1170,11 +1170,9 @@ PLIST_API void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length) ...@@ -1170,11 +1170,9 @@ PLIST_API void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length)
uint64_t offset_table_index = 0; uint64_t offset_table_index = 0;
bytearray_t *bplist_buff = NULL; bytearray_t *bplist_buff = NULL;
uint64_t i = 0; uint64_t i = 0;
uint8_t *buff = NULL;
uint64_t *offsets = NULL; uint64_t *offsets = NULL;
bplist_trailer_t trailer; bplist_trailer_t trailer;
uint64_t objects_len = 0; uint64_t objects_len = 0;
uint64_t buff_len = 0;
//check for valid input //check for valid input
if (!plist || !plist_bin || *plist_bin || !length) if (!plist || !plist_bin || *plist_bin || !length)
...@@ -1298,13 +1296,11 @@ PLIST_API void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length) ...@@ -1298,13 +1296,11 @@ PLIST_API void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length)
switch (data->type) switch (data->type)
{ {
case PLIST_BOOLEAN: case PLIST_BOOLEAN: {
buff = (uint8_t *) malloc(sizeof(uint8_t)); uint8_t b = data->boolval ? BPLIST_TRUE : BPLIST_FALSE;
buff[0] = data->boolval ? BPLIST_TRUE : BPLIST_FALSE; byte_array_append(bplist_buff, &b, 1);
byte_array_append(bplist_buff, buff, sizeof(uint8_t));
free(buff);
break; break;
}
case PLIST_UINT: case PLIST_UINT:
if (data->length == 16) { if (data->length == 16) {
write_uint(bplist_buff, data->intval); write_uint(bplist_buff, data->intval);
...@@ -1353,8 +1349,7 @@ PLIST_API void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length) ...@@ -1353,8 +1349,7 @@ PLIST_API void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length)
hash_table_destroy(ref_table); hash_table_destroy(ref_table);
//write offsets //write offsets
buff_len = bplist_buff->len; offset_size = get_needed_bytes(bplist_buff->len);
offset_size = get_needed_bytes(buff_len);
offset_table_index = bplist_buff->len; offset_table_index = bplist_buff->len;
for (i = 0; i < num_objects; i++) { for (i = 0; i < num_objects; i++) {
uint64_t offset = be64toh(offsets[i]); uint64_t offset = be64toh(offsets[i]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment