diff options
author | John Hawthorn <john@hawthorn.email> | 2019-12-27 18:43:46 -0800 |
---|---|---|
committer | John Hawthorn <john@hawthorn.email> | 2019-12-27 18:48:31 -0800 |
commit | 9dfb287b86b431d57dd67464aaa1a5863d63e078 (patch) | |
tree | 3765e796e1f5ee254d5ba3c53250c14e80c43651 | |
parent | b76efa71c6b33439e098d66e1e08be665622d7a3 (diff) |
Use malloc in match_positions to avoid VLA
-rw-r--r-- | src/match.c | 11 |
1 files 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; } |