[parser] Fixing possible invalid writes in training for values beginning with a separator

This commit is contained in:
Al
2015-12-11 02:05:05 -05:00
parent 743b74aea5
commit 671dd4a5d2
2 changed files with 5 additions and 7 deletions

View File

@@ -51,13 +51,12 @@ bool address_parser_data_set_tokenize_line(address_parser_data_set_t *data_set,
label = str + last_separator_index + 1; label = str + last_separator_index + 1;
uint32_t last_separator_type = ADDRESS_SEPARATOR_NONE;
if (strcmp(label, FIELD_SEPARATOR_LABEL) == 0) { if (strcmp(label, FIELD_SEPARATOR_LABEL) == 0) {
last_separator_type = uint32_array_pop(separators); uint32_array_pop(separators);
uint32_array_push(separators, ADDRESS_SEPARATOR_FIELD | ADDRESS_SEPARATOR_FIELD_INTERNAL); uint32_array_push(separators, ADDRESS_SEPARATOR_FIELD | ADDRESS_SEPARATOR_FIELD_INTERNAL);
continue; continue;
} else if (strcmp(label, SEPARATOR_LABEL) == 0) { } else if (strcmp(label, SEPARATOR_LABEL) == 0) {
last_separator_type = uint32_array_pop(separators); uint32_array_pop(separators);
uint32_array_push(separators, ADDRESS_SEPARATOR_FIELD_INTERNAL); uint32_array_push(separators, ADDRESS_SEPARATOR_FIELD_INTERNAL);
continue; continue;
} }

View File

@@ -11,7 +11,6 @@
name *array = malloc(sizeof(name)); \ name *array = malloc(sizeof(name)); \
if (array == NULL) return NULL; \ if (array == NULL) return NULL; \
array->n = array->m = 0; \ array->n = array->m = 0; \
array->a = NULL; \
array->a = malloc(size * sizeof(type)); \ array->a = malloc(size * sizeof(type)); \
if (array->a == NULL) return NULL; \ if (array->a == NULL) return NULL; \
array->m = size; \ array->m = size; \
@@ -39,12 +38,12 @@
} \ } \
static inline void name##_extend(name *array, name *other) { \ static inline void name##_extend(name *array, name *other) { \
size_t new_size = array->n + other->n; \ size_t new_size = array->n + other->n; \
if (new_size >= array->m) name##_resize(array, new_size); \ if (new_size > array->m) name##_resize(array, new_size); \
memcpy(array->a + array->n, other->a, other->n * sizeof(type)); \ memcpy(array->a + array->n, other->a, other->n * sizeof(type)); \
array->n = new_size; \ array->n = new_size; \
} \ } \
static inline type name##_pop(name *array) { \ static inline void name##_pop(name *array) { \
return array->a[--array->n]; \ if (array->n > 0) array->n--; \
} \ } \
static inline void name##_clear(name *array) { \ static inline void name##_clear(name *array) { \
array->n = 0; \ array->n = 0; \