From f7a62107b72152cd19dab1c13c027e4190a1997c Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Fri, 27 Dec 2019 19:39:50 -0800 Subject: Avoid VLA in tty_interface --- src/match.c | 2 -- src/match.h | 2 ++ src/tty_interface.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/match.c b/src/match.c index 4aaf1b4..a0c0785 100644 --- a/src/match.c +++ b/src/match.c @@ -32,8 +32,6 @@ int has_match(const char *needle, const char *haystack) { #define max(a, b) (((a) > (b)) ? (a) : (b)) -#define MATCH_MAX_LEN 1024 - struct match_struct { int needle_len; int haystack_len; diff --git a/src/match.h b/src/match.h index 0fa7b6f..d4f292c 100644 --- a/src/match.h +++ b/src/match.h @@ -7,6 +7,8 @@ typedef double score_t; #define SCORE_MAX INFINITY #define SCORE_MIN -INFINITY +#define MATCH_MAX_LEN 1024 + int has_match(const char *needle, const char *haystack); score_t match_positions(const char *needle, const char *haystack, size_t *positions); score_t match(const char *needle, const char *haystack); diff --git a/src/tty_interface.c b/src/tty_interface.c index 225f33a..e87301d 100644 --- a/src/tty_interface.c +++ b/src/tty_interface.c @@ -36,8 +36,8 @@ static void draw_match(tty_interface_t *state, const char *choice, int selected) char *search = state->last_search; int n = strlen(search); - size_t positions[n + 1]; - for (int i = 0; i < n + 1; i++) + size_t positions[MATCH_MAX_LEN]; + for (int i = 0; i < n + 1 && i < MATCH_MAX_LEN; i++) positions[i] = -1; score_t score = match_positions(search, choice, &positions[0]); -- cgit v1.2.3