From 537b543d821e6808ba0508723fa6e9adabb61391 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Thu, 29 Nov 2018 01:31:26 +0100 Subject: bplist: Remove redundant calls to strlen() --- src/bplist.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/bplist.c b/src/bplist.c index a9724b8..1ecbd66 100644 --- a/src/bplist.c +++ b/src/bplist.c @@ -1023,9 +1023,8 @@ static void write_data(bytearray_t * bplist, uint8_t * val, uint64_t size) write_raw_data(bplist, BPLIST_DATA, val, size); } -static void write_string(bytearray_t * bplist, char *val) +static void write_string(bytearray_t * bplist, char *val, uint64_t size) { - uint64_t size = strlen(val); write_raw_data(bplist, BPLIST_STRING, (uint8_t *) val, size); } @@ -1188,7 +1187,6 @@ PLIST_API void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length) uint64_t *offsets = NULL; bplist_trailer_t trailer; //for string - long len = 0; long items_read = 0; long items_written = 0; uint16_t *unicodestr = NULL; @@ -1256,14 +1254,13 @@ PLIST_API void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length) case PLIST_KEY: case PLIST_STRING: - len = strlen(data->strval); - if ( is_ascii_string(data->strval, len) ) + if ( is_ascii_string(data->strval, data->length) ) { - write_string(bplist_buff, data->strval); + write_string(bplist_buff, data->strval, data->length); } else { - unicodestr = plist_utf8_to_utf16(data->strval, len, &items_read, &items_written); + unicodestr = plist_utf8_to_utf16(data->strval, data->length, &items_read, &items_written); write_unicode(bplist_buff, unicodestr, items_written); free(unicodestr); } -- cgit v1.1-32-gdbae