diff --git a/src/utils/acmp.cc b/src/utils/acmp.cc index c1614b3fe5..1ca93b9848 100644 --- a/src/utils/acmp.cc +++ b/src/utils/acmp.cc @@ -387,17 +387,20 @@ if (parser->is_active != 0) return -1; child->pattern = (char *)""; child->letter = letter; child->depth = i; - child->text = (char *)calloc(1, strlen(pattern) + 2); + child->text = (char *)calloc(1, i + 2); /* ENH: Check alloc succeded */ - for (j = 0; j <= i; j++) child->text[j] = pattern[j]; + for (j = 0; j <= i; j++) { + child->text[j] = pattern[j]; + } } if (i == length - 1) { if (child->is_last == 0) { parser->dict_count++; child->is_last = 1; - child->pattern = (char *)calloc(1, strlen(pattern) + 2); + child->pattern = (char *)calloc(1, length + 1); /* ENH: Check alloc succeded */ - strcpy(child->pattern, pattern); + memcpy(child->pattern, pattern, length); + child->pattern[length] = '\0'; } child->callback = callback; child->callback_data = data;