From be3a4b6ca81c4e9dd3faa81dc01f53468ceed3ad Mon Sep 17 00:00:00 2001 From: Felipe Oliveira Carvalho Date: Mon, 9 Jun 2014 00:02:50 -0300 Subject: ga_growsize should be >= 1 I know it could be 0 sometimes. Running the tests with `assert(gap->ga_growsize > 0)` in ga_grow() crashes nvim while running the tests. - Add a setter for ga_growsize that checks whether the value passed is >=1 (log in case it's not) - log when ga_grow() tries to use a ga_growsize that's not >=1 - use GA_EMPTY_INIT_VALUE is many places --- src/nvim/ex_cmds2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ex_cmds2.c') diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index 93822ebcfe..af6227d965 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -2790,7 +2790,7 @@ char_u *getsourceline(int c, void *cookie, int indent) /* Adjust the growsize to the current length to speed up * concatenating many lines. */ if (ga.ga_len > 400) { - ga.ga_growsize = (ga.ga_len > 8000) ? 8000 : ga.ga_len; + ga_set_growsize(&ga, (ga.ga_len > 8000) ? 8000 : ga.ga_len); } ga_concat(&ga, p + 1); } -- cgit From 45e7814e6aa8aacd8772056863d13770d4e30b48 Mon Sep 17 00:00:00 2001 From: Felipe Oliveira Carvalho Date: Wed, 25 Jun 2014 22:03:58 -0300 Subject: Introduce GA_APPEND() This macro is used to append an element to a growable array. It replaces this common idiom: ga_grow(&ga, 1); ((item_type *)ga.ga_data)[ga.ga_len] = item; ++ga.ga_len; --- src/nvim/ex_cmds2.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src/nvim/ex_cmds2.c') diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index af6227d965..0b0026829f 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -1525,8 +1525,7 @@ void get_arglist(garray_T *gap, char_u *str) { ga_init(gap, (int)sizeof(char_u *), 20); while (*str != NUL) { - ga_grow(gap, 1); - ((char_u **)gap->ga_data)[gap->ga_len++] = str; + GA_APPEND(char_u *, gap, str); /* Isolate one argument, change it in-place, put a NUL after it. */ str = do_one_arg(str); @@ -3332,13 +3331,12 @@ static char_u **find_locales(void) loc = (char_u *)strtok((char *)locale_a, "\n"); while (loc != NULL) { - ga_grow(&locales_ga, 1); loc = vim_strsave(loc); - - ((char_u **)locales_ga.ga_data)[locales_ga.ga_len++] = loc; + GA_APPEND(char_u *, &locales_ga, loc); loc = (char_u *)strtok(NULL, "\n"); } free(locale_a); + // Guarantee that .ga_data is NULL terminated ga_grow(&locales_ga, 1); ((char_u **)locales_ga.ga_data)[locales_ga.ga_len] = NULL; return (char_u **)locales_ga.ga_data; -- cgit