From 9dfb287b86b431d57dd67464aaa1a5863d63e078 Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Fri, 27 Dec 2019 18:43:46 -0800 Subject: Use malloc in match_positions to avoid VLA --- src/match.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/match.c b/src/match.c index e0cae96..b5c134b 100644 --- a/src/match.c +++ b/src/match.c @@ -186,7 +186,9 @@ score_t match_positions(const char *needle, const char *haystack, size_t *positi * D[][] Stores the best score for this position ending with a match. * M[][] Stores the best possible score at this position. */ - score_t D[n][m], M[n][m]; + score_t (*D)[MATCH_MAX_LEN], (*M)[MATCH_MAX_LEN]; + M = malloc(sizeof(score_t) * MATCH_MAX_LEN * n); + D = malloc(sizeof(score_t) * MATCH_MAX_LEN * n); score_t *last_D, *last_M; score_t *curr_D, *curr_M; @@ -230,5 +232,10 @@ score_t match_positions(const char *needle, const char *haystack, size_t *positi } } - return M[n - 1][m - 1]; + score_t result = M[n - 1][m - 1]; + + free(M); + free(D); + + return result; } -- cgit v1.2.3