diff options
author | Linus Walleij <triad@df.lth.se> | 2006-08-29 15:30:11 +0000 |
---|---|---|
committer | Linus Walleij <triad@df.lth.se> | 2006-08-29 15:30:11 +0000 |
commit | 958441f8ed3e704cf07c9f600730f90a80a0d424 (patch) | |
tree | 73ec632870ddf5aeb4b021e4950d660acf3e0788 | |
parent | 735f41692934a716158cf051d76e988febeca7ee (diff) | |
download | libmtp-0-0-16.tar.gz |
Packing bug...libmtp-0-0-16
-rw-r--r-- | src/ptp-pack.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/ptp-pack.c b/src/ptp-pack.c index f3be8c6..df2f4cb 100644 --- a/src/ptp-pack.c +++ b/src/ptp-pack.c @@ -159,25 +159,28 @@ ptp_pack_string(PTPParams *params, char *string, unsigned char* data, uint16_t o *len=0; return; } - *len = (uint8_t) packedlen; - + /* +1 for the length byte, no zero 0x0000 terminator */ htod8a(&data[offset],packedlen+1); for (i=0;i<packedlen && i< PTP_MAXSTRLEN; i++) { htod16a(&data[offset+i*2+1],ucs2str[i]); } + + /* The returned length is in number of characters */ + *len = (uint8_t) packedlen; } static inline unsigned char * ptp_get_packed_stringcopy(PTPParams *params, char *string, uint32_t *packed_size) { - uint8_t packed[PTP_MAXSTRLEN+3], len; +uint8_t packed[PTP_MAXSTRLEN+3], len; size_t plen; unsigned char *retcopy = NULL; ptp_pack_string(params, string, (unsigned char*) packed, 0, &len); - plen = len + 1; - /* Assure proper termination */ + /* returned length is in characters, then one byte for string length */ + plen = len*2 + 1; + /* Assure proper termination, two zero bytes */ packed[plen] = 0x00; packed[plen+1] = 0x00; /* Include terminator */ |