diff options
Diffstat (limited to 'toxav/msi.c')
-rw-r--r-- | toxav/msi.c | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/toxav/msi.c b/toxav/msi.c index 031f1e54..b5d3779f 100644 --- a/toxav/msi.c +++ b/toxav/msi.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #endif /* HAVE_CONFIG_H */ | 27 | #endif /* HAVE_CONFIG_H */ |
28 | 28 | ||
29 | #include "../toxcore/logger.h" | 29 | #include "../toxcore/logger.h" |
30 | #include "../toxcore/util.h" | ||
30 | 31 | ||
31 | #include "msi.h" | 32 | #include "msi.h" |
32 | #include "event.h" | 33 | #include "event.h" |
@@ -37,8 +38,6 @@ | |||
37 | #include <string.h> | 38 | #include <string.h> |
38 | #include <stdlib.h> | 39 | #include <stdlib.h> |
39 | 40 | ||
40 | #define inline__ inline __attribute__((always_inline)) | ||
41 | |||
42 | #define same(x, y) strcmp((const char*) x, (const char*) y) == 0 | 41 | #define same(x, y) strcmp((const char*) x, (const char*) y) == 0 |
43 | 42 | ||
44 | #define MSI_MAXMSG_SIZE 1024 | 43 | #define MSI_MAXMSG_SIZE 1024 |
@@ -226,13 +225,12 @@ int parse_raw_data ( MSIMessage *msg, const uint8_t *data, uint16_t length ) | |||
226 | ( memcmp(iterator, descriptor, size_const) == 0){ /* Okay */ \ | 225 | ( memcmp(iterator, descriptor, size_const) == 0){ /* Okay */ \ |
227 | iterator += size_const; /* Set iterator at begining of value part */ \ | 226 | iterator += size_const; /* Set iterator at begining of value part */ \ |
228 | if ( *iterator != value_byte ) { assert(0); return -1; }\ | 227 | if ( *iterator != value_byte ) { assert(0); return -1; }\ |
229 | iterator ++;\ | 228 | iterator ++;\ |
230 | uint16_t _value_size = (uint16_t) *(iterator ) << 8 | \ | 229 | uint16_t _value_size; bytes_to_U16(&_value_size, iterator); \ |
231 | (uint16_t) *(iterator + 1); \ | 230 | header.header_value = calloc(sizeof(uint8_t), _value_size); \ |
232 | header.header_value = calloc(sizeof(uint8_t), _value_size); \ | 231 | header.size = _value_size; \ |
233 | header.size = _value_size; \ | 232 | memcpy(header.header_value, iterator + 2, _value_size);\ |
234 | memcpy(header.header_value, iterator + 2, _value_size);\ | 233 | iterator = iterator + 2 + _value_size; /* set iterator at new header or end_byte */ } |
235 | iterator = iterator + 2 + _value_size; /* set iterator at new header or end_byte */ } | ||
236 | 234 | ||
237 | if ( msg == NULL ) { | 235 | if ( msg == NULL ) { |
238 | LOGGER_ERROR("Could not parse message: no storage!"); | 236 | LOGGER_ERROR("Could not parse message: no storage!"); |
@@ -249,9 +247,9 @@ if ( *iterator != value_byte ) { assert(0); return -1; }\ | |||
249 | 247 | ||
250 | if ( *_it == field_byte && itedlen < length ) { | 248 | if ( *_it == field_byte && itedlen < length ) { |
251 | 249 | ||
252 | uint16_t _size = ( uint16_t ) * ( _it + 1 ) << 8 | | 250 | uint16_t _size; |
253 | ( uint16_t ) * ( _it + 2 ); | 251 | bytes_to_U16(&_size, _it + 1); |
254 | 252 | ||
255 | if ( itedlen + _size > length ) return -1; | 253 | if ( itedlen + _size > length ) return -1; |
256 | 254 | ||
257 | _it += 3; /* place it at the field value beginning */ | 255 | _it += 3; /* place it at the field value beginning */ |