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/regexp.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/regexp.c') diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index ea61436e05..29f090c6b7 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -3180,8 +3180,8 @@ static int reg_line_lbr; /* "\n" in string is line break */ * or regbehind_T. * "backpos_T" is a table with backpos_T for BACK */ -static garray_T regstack = {0, 0, 0, 0, NULL}; -static garray_T backpos = {0, 0, 0, 0, NULL}; +static garray_T regstack = GA_EMPTY_INIT_VALUE; +static garray_T backpos = GA_EMPTY_INIT_VALUE; /* * Both for regstack and backpos tables we use the following strategy of @@ -3319,13 +3319,13 @@ static long bt_regexec_both(char_u *line, * onto the regstack. */ ga_init(®stack, 1, REGSTACK_INITIAL); ga_grow(®stack, REGSTACK_INITIAL); - regstack.ga_growsize = REGSTACK_INITIAL * 8; + ga_set_growsize(®stack, REGSTACK_INITIAL * 8); } if (backpos.ga_data == NULL) { ga_init(&backpos, sizeof(backpos_T), BACKPOS_INITIAL); ga_grow(&backpos, BACKPOS_INITIAL); - backpos.ga_growsize = BACKPOS_INITIAL * 8; + ga_set_growsize(&backpos, BACKPOS_INITIAL * 8); } if (REG_MULTI) { -- cgit From 5ed74cfb7c67f79441343ec90548f333dad1729b Mon Sep 17 00:00:00 2001 From: Felipe Oliveira Carvalho Date: Wed, 11 Jun 2014 03:01:46 -0300 Subject: Introduce ga_append_via_ptr() and GA_APPEND_VIA_PTR() Similar to GA_APPEND(). Replaces this pattern: ga_grow(&ga, 1); item_type *p = ((item_type *)ga.ga_data) + ga.ga_len; p->field1 = v1; p->field2 = v2; ga.ga_len++; --- src/nvim/regexp.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'src/nvim/regexp.c') diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index 29f090c6b7..0ead83e0d4 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -4177,7 +4177,6 @@ regmatch ( case BACK: { int i; - backpos_T *bp; /* * When we run into BACK we need to check if we don't keep @@ -4187,17 +4186,13 @@ regmatch ( * The positions are stored in "backpos" and found by the * current value of "scan", the position in the RE program. */ - bp = (backpos_T *)backpos.ga_data; + backpos_T *bp = (backpos_T *)backpos.ga_data; for (i = 0; i < backpos.ga_len; ++i) if (bp[i].bp_scan == scan) break; if (i == backpos.ga_len) { - /* First time at this BACK, make room to store the pos. */ - ga_grow(&backpos, 1); - /* get "ga_data" again, it may have changed */ - bp = (backpos_T *)backpos.ga_data; - bp[i].bp_scan = scan; - ++backpos.ga_len; + backpos_T *p = GA_APPEND_VIA_PTR(backpos_T, &backpos); + p->bp_scan = scan; } else if (reg_save_equal(&bp[i].bp_pos)) /* Still at same position as last time, fail. */ status = RA_NOMATCH; -- cgit