[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;
uint32_t last_separator_type = ADDRESS_SEPARATOR_NONE;
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);
continue;
} 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);
continue;
}

View File

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