diff options
author | Felipe Oliveira Carvalho <felipekde@gmail.com> | 2014-04-07 22:28:33 -0300 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2014-04-11 12:57:59 -0300 |
commit | f6b0e335e1f638e3c2d97e6886976d28d3798c32 (patch) | |
tree | c44159f894a036baa9e880f53cf3a2c3ba36adb7 | |
parent | 457bb2615154946d273d75e07f5d5a936f50ede0 (diff) | |
download | rneovim-f6b0e335e1f638e3c2d97e6886976d28d3798c32.tar.gz rneovim-f6b0e335e1f638e3c2d97e6886976d28d3798c32.tar.bz2 rneovim-f6b0e335e1f638e3c2d97e6886976d28d3798c32.zip |
Remove OOM error handling code after ga_grow() calls
-rw-r--r-- | src/charset.c | 18 | ||||
-rw-r--r-- | src/digraph.c | 18 | ||||
-rw-r--r-- | src/eval.c | 51 | ||||
-rw-r--r-- | src/ex_cmds.c | 25 | ||||
-rw-r--r-- | src/ex_cmds2.c | 52 | ||||
-rw-r--r-- | src/ex_docmd.c | 16 | ||||
-rw-r--r-- | src/ex_getln.c | 35 | ||||
-rw-r--r-- | src/fileio.c | 7 | ||||
-rw-r--r-- | src/fold.c | 29 | ||||
-rw-r--r-- | src/garray.c | 22 | ||||
-rw-r--r-- | src/garray.h | 2 | ||||
-rw-r--r-- | src/main.c | 4 | ||||
-rw-r--r-- | src/menu.c | 39 | ||||
-rw-r--r-- | src/message.c | 33 | ||||
-rw-r--r-- | src/option.c | 18 | ||||
-rw-r--r-- | src/os/users.c | 4 | ||||
-rw-r--r-- | src/path.c | 7 | ||||
-rw-r--r-- | src/regexp.c | 26 | ||||
-rw-r--r-- | src/spell.c | 99 | ||||
-rw-r--r-- | src/syntax.c | 186 | ||||
-rw-r--r-- | src/tag.c | 12 | ||||
-rw-r--r-- | src/undo.c | 5 | ||||
-rw-r--r-- | src/window.c | 14 |
23 files changed, 318 insertions, 404 deletions
diff --git a/src/charset.c b/src/charset.c index e85f369c61..8daac20f02 100644 --- a/src/charset.c +++ b/src/charset.c @@ -423,9 +423,7 @@ char_u* str_foldcase(char_u *str, int orglen, char_u *buf, int buflen) if (buf == NULL) { ga_init(&ga, 1, 10); - if (ga_grow(&ga, len + 1) == FAIL) { - return NULL; - } + ga_grow(&ga, len + 1); memmove(ga.ga_data, str, (size_t)len); ga.ga_len = len; } else { @@ -461,12 +459,14 @@ char_u* str_foldcase(char_u *str, int orglen, char_u *buf, int buflen) // characters forward or backward. if (olen != nlen) { if (nlen > olen) { - if ((buf == NULL) - ? (ga_grow(&ga, nlen - olen + 1) == FAIL) - : (len + nlen - olen >= buflen)) { - // out of memory, keep old char - lc = c; - nlen = olen; + if (buf == NULL) { + ga_grow(&ga, nlen - olen + 1); + } else { + if (len + nlen - olen >= buflen) { + // out of memory, keep old char + lc = c; + nlen = olen; + } } } diff --git a/src/digraph.c b/src/digraph.c index ea307ad4e2..88f183be4f 100644 --- a/src/digraph.c +++ b/src/digraph.c @@ -1618,13 +1618,12 @@ void putdigraph(char_u *str) // Add a new digraph to the table. if (i == user_digraphs.ga_len) { - if (ga_grow(&user_digraphs, 1) == OK) { - dp = (digr_T *)user_digraphs.ga_data + user_digraphs.ga_len; - dp->char1 = char1; - dp->char2 = char2; - dp->result = n; - ++user_digraphs.ga_len; - } + ga_grow(&user_digraphs, 1); + dp = (digr_T *)user_digraphs.ga_data + user_digraphs.ga_len; + dp->char1 = char1; + dp->char2 = char2; + dp->result = n; + ++user_digraphs.ga_len; } } } @@ -1809,9 +1808,8 @@ void ex_loadkeymap(exarg_T *eap) p = skipwhite(line); - if ((*p != '"') - && (*p != NUL) - && (ga_grow(&curbuf->b_kmap_ga, 1) == OK)) { + if ((*p != '"') && (*p != NUL)) { + ga_grow(&curbuf->b_kmap_ga, 1); kp = (kmap_T *)curbuf->b_kmap_ga.ga_data + curbuf->b_kmap_ga.ga_len; s = skiptowhite(p); kp->from = vim_strnsave(p, (int)(s - p)); diff --git a/src/eval.c b/src/eval.c index 7459756946..e1f7de3707 100644 --- a/src/eval.c +++ b/src/eval.c @@ -1116,11 +1116,9 @@ void var_redir_str(char_u *value, int value_len) else len = value_len; /* Append only "value_len" characters */ - if (ga_grow(&redir_ga, len) == OK) { - memmove((char *)redir_ga.ga_data + redir_ga.ga_len, value, len); - redir_ga.ga_len += len; - } else - var_redir_stop(); + ga_grow(&redir_ga, len); + memmove((char *)redir_ga.ga_data + redir_ga.ga_len, value, len); + redir_ga.ga_len += len; } /* @@ -5834,8 +5832,7 @@ list_join_inner ( * multiple copy operations. Add 2 for a tailing ']' and NUL. */ if (join_gap->ga_len >= 2) sumlen += (int)STRLEN(sep) * (join_gap->ga_len - 1); - if (ga_grow(gap, sumlen + 2) == FAIL) - return FAIL; + ga_grow(gap, sumlen + 2); for (i = 0; i < join_gap->ga_len && !got_int; ++i) { if (first) @@ -10813,13 +10810,10 @@ static void f_inputrestore(typval_T *argvars, typval_T *rettv) static void f_inputsave(typval_T *argvars, typval_T *rettv) { /* Add an entry to the stack of typeahead storage. */ - if (ga_grow(&ga_userinput, 1) == OK) { - save_typeahead((tasave_T *)(ga_userinput.ga_data) - + ga_userinput.ga_len); - ++ga_userinput.ga_len; - /* default return is zero == OK */ - } else - rettv->vval.v_number = 1; /* Failed */ + ga_grow(&ga_userinput, 1); + save_typeahead((tasave_T *)(ga_userinput.ga_data) + + ga_userinput.ga_len); + ++ga_userinput.ga_len; } /* @@ -16537,7 +16531,8 @@ void new_script_vars(scid_T id) hashtab_T *ht; scriptvar_T *sv; - if (ga_grow(&ga_scripts, (int)(id - ga_scripts.ga_len)) == OK) { + ga_grow(&ga_scripts, (int)(id - ga_scripts.ga_len)); + { /* Re-allocating ga_data means that an ht_array pointing to * ht_smallarray becomes invalid. We can recognize this: ht_mask is * at its init value. Also reset "v_dict", it's always the same. */ @@ -17148,11 +17143,7 @@ void ex_execute(exarg_T *eap) if (!eap->skip) { p = get_tv_string(&rettv); len = (int)STRLEN(p); - if (ga_grow(&ga, len + 2) == FAIL) { - clear_tv(&rettv); - ret = FAIL; - break; - } + ga_grow(&ga, len + 2); if (ga.ga_len) ((char_u *)(ga.ga_data))[ga.ga_len++] = ' '; STRCPY((char_u *)(ga.ga_data) + ga.ga_len, p); @@ -17440,8 +17431,7 @@ void ex_function(exarg_T *eap) EMSG2(_("E125: Illegal argument: %s"), arg); break; } - if (ga_grow(&newargs, 1) == FAIL) - goto erret; + ga_grow(&newargs, 1); c = *p; *p = NUL; arg = vim_strsave(arg); @@ -17631,11 +17621,7 @@ void ex_function(exarg_T *eap) } /* Add the line to the function. */ - if (ga_grow(&newlines, 1 + sourcing_lnum_off) == FAIL) { - if (line_arg == NULL) - vim_free(theline); - goto erret; - } + ga_grow(&newlines, 1 + sourcing_lnum_off); /* Copy the line to newly allocated memory. get_one_sourceline() * allocates 250 bytes per line, this saves 80% on average. The cost @@ -18320,7 +18306,8 @@ script_autoload ( ret = FALSE; /* was loaded already */ else { /* Remember the name if it wasn't loaded already. */ - if (i == ga_loaded.ga_len && ga_grow(&ga_loaded, 1) == OK) { + if (i == ga_loaded.ga_len) { + ga_grow(&ga_loaded, 1); ((char_u **)ga_loaded.ga_data)[ga_loaded.ga_len++] = scriptname; tofree = NULL; } @@ -19715,12 +19702,8 @@ char_u *do_string_sub(char_u *str, char_u *pat, char_u *sub, char_u *flags) * - The text after the match. */ sublen = vim_regsub(®match, sub, tail, FALSE, TRUE, FALSE); - if (ga_grow(&ga, (int)(STRLEN(tail) + sublen - - (regmatch.endp[0] - regmatch.startp[0]))) == - FAIL) { - ga_clear(&ga); - break; - } + ga_grow(&ga, (int)(STRLEN(tail) + sublen - + (regmatch.endp[0] - regmatch.startp[0]))); /* copy the text up to where the match is */ i = (int)(regmatch.startp[0] - tail); diff --git a/src/ex_cmds.c b/src/ex_cmds.c index 8b3a2a4bfd..7b04171286 100644 --- a/src/ex_cmds.c +++ b/src/ex_cmds.c @@ -5426,8 +5426,7 @@ void ex_helptags(exarg_T *eap) break; if (j == ga.ga_len) { /* New language, add it. */ - if (ga_grow(&ga, 2) == FAIL) - break; + ga_grow(&ga, 2); ((char_u *)ga.ga_data)[ga.ga_len++] = lang[0]; ((char_u *)ga.ga_data)[ga.ga_len++] = lang[1]; } @@ -5520,18 +5519,11 @@ helptags_one ( ga_init(&ga, (int)sizeof(char_u *), 100); if (add_help_tags || path_full_compare((char_u *)"$VIMRUNTIME/doc", dir, FALSE) == kEqualFiles) { - if (ga_grow(&ga, 1) == FAIL) - got_int = TRUE; - else { - s = alloc(18 + (unsigned)STRLEN(tagfname)); - if (s == NULL) - got_int = TRUE; - else { - sprintf((char *)s, "help-tags\t%s\t1\n", tagfname); - ((char_u **)ga.ga_data)[ga.ga_len] = s; - ++ga.ga_len; - } - } + ga_grow(&ga, 1); + s = alloc(18 + (unsigned)STRLEN(tagfname)); + sprintf((char *)s, "help-tags\t%s\t1\n", tagfname); + ((char_u **)ga.ga_data)[ga.ga_len] = s; + ++ga.ga_len; } /* @@ -5598,10 +5590,7 @@ helptags_one ( || s[1] == '\0')) { *p2 = '\0'; ++p1; - if (ga_grow(&ga, 1) == FAIL) { - got_int = TRUE; - break; - } + ga_grow(&ga, 1); s = alloc((unsigned)(p2 - p1 + STRLEN(fname) + 2)); if (s == NULL) { got_int = TRUE; diff --git a/src/ex_cmds2.c b/src/ex_cmds2.c index 93288da2ec..b5be98a491 100644 --- a/src/ex_cmds2.c +++ b/src/ex_cmds2.c @@ -413,8 +413,8 @@ dbg_parsearg ( struct debuggy *bp; int here = FALSE; - if (ga_grow(gap, 1) == FAIL) - return FAIL; + ga_grow(gap, 1); + bp = &DEBUGGY(gap, gap->ga_len); /* Find "func" or "file". */ @@ -1543,10 +1543,7 @@ int get_arglist(garray_T *gap, char_u *str) { ga_init(gap, (int)sizeof(char_u *), 20); while (*str != NUL) { - if (ga_grow(gap, 1) == FAIL) { - ga_clear(gap); - return FAIL; - } + ga_grow(gap, 1); ((char_u **)gap->ga_data)[gap->ga_len++] = str; /* Isolate one argument, change it in-place, put a NUL after it. */ @@ -1771,15 +1768,15 @@ void ex_args(exarg_T *eap) /* * ":argslocal": make a local copy of the global argument list. */ - if (ga_grow(gap, GARGCOUNT) == OK) - for (i = 0; i < GARGCOUNT; ++i) - if (GARGLIST[i].ae_fname != NULL) { - AARGLIST(curwin->w_alist)[gap->ga_len].ae_fname = - vim_strsave(GARGLIST[i].ae_fname); - AARGLIST(curwin->w_alist)[gap->ga_len].ae_fnum = - GARGLIST[i].ae_fnum; - ++gap->ga_len; - } + ga_grow(gap, GARGCOUNT); + for (i = 0; i < GARGCOUNT; ++i) + if (GARGLIST[i].ae_fname != NULL) { + AARGLIST(curwin->w_alist)[gap->ga_len].ae_fname = + vim_strsave(GARGLIST[i].ae_fname); + AARGLIST(curwin->w_alist)[gap->ga_len].ae_fnum = + GARGLIST[i].ae_fnum; + ++gap->ga_len; + } } } @@ -2120,7 +2117,7 @@ void ex_listdo(exarg_T *eap) * Add files[count] to the arglist of the current window after arg "after". * The file names in files[count] must have been allocated and are taken over. * Files[] itself is not taken over. - * Returns index of first added argument. Returns -1 when failed (out of mem). + * Returns index of first added argument. */ static int alist_add_list ( @@ -2131,7 +2128,8 @@ alist_add_list ( { int i; - if (ga_grow(&ALIST(curwin)->al_ga, count) == OK) { + ga_grow(&ALIST(curwin)->al_ga, count); + { if (after < 0) after = 0; if (after > ARGCOUNT) @@ -2148,10 +2146,6 @@ alist_add_list ( ++curwin->w_arg_idx; return after; } - - for (i = 0; i < count; ++i) - vim_free(files[i]); - return -1; } @@ -2661,9 +2655,7 @@ do_source ( } if (current_SID == 0) { current_SID = ++last_current_SID; - if (ga_grow(&script_items, (int)(current_SID - script_items.ga_len)) - == FAIL) - goto almosttheend; + ga_grow(&script_items, (int)(current_SID - script_items.ga_len)); while (script_items.ga_len < current_SID) { ++script_items.ga_len; SCRIPT_ITEM(script_items.ga_len).sn_name = NULL; @@ -2746,7 +2738,6 @@ do_source ( && debug_break_level == ex_nesting_level) ++debug_break_level; -almosttheend: current_SID = save_current_SID; restore_funccal(save_funccalp); if (do_profiling == PROF_YES) @@ -2993,8 +2984,7 @@ static char_u *get_one_sourceline(struct source_cookie *sp) sourcing_lnum++; for (;; ) { /* make room to read at least 120 (more) characters */ - if (ga_grow(&ga, 120) == FAIL) - break; + ga_grow(&ga, 120); buf = (char_u *)ga.ga_data; #ifdef USE_CR @@ -3528,8 +3518,7 @@ static char_u **find_locales(void) loc = (char_u *)strtok((char *)locale_a, "\n"); while (loc != NULL) { - if (ga_grow(&locales_ga, 1) == FAIL) - break; + ga_grow(&locales_ga, 1); loc = vim_strsave(loc); if (loc == NULL) break; @@ -3538,10 +3527,7 @@ static char_u **find_locales(void) loc = (char_u *)strtok(NULL, "\n"); } vim_free(locale_a); - if (ga_grow(&locales_ga, 1) == FAIL) { - ga_clear(&locales_ga); - return NULL; - } + ga_grow(&locales_ga, 1); ((char_u **)locales_ga.ga_data)[locales_ga.ga_len] = NULL; return (char_u **)locales_ga.ga_data; } diff --git a/src/ex_docmd.c b/src/ex_docmd.c index a5cd1863a0..a5d4b3bd2f 100644 --- a/src/ex_docmd.c +++ b/src/ex_docmd.c @@ -1,4 +1,4 @@ -/* vi:set ts=8 sts=4 sw=4: +/* vi:set ts=2 sts=2 sw=2: * * VIM - Vi IMproved by Bram Moolenaar * @@ -1179,8 +1179,7 @@ static char_u *get_loop_line(int c, void *cookie, int indent) */ static int store_loop_line(garray_T *gap, char_u *line) { - if (ga_grow(gap, 1) == FAIL) - return FAIL; + ga_grow(gap, 1); ((wcmd_T *)(gap->ga_data))[gap->ga_len].line = vim_strsave(line); ((wcmd_T *)(gap->ga_data))[gap->ga_len].lnum = sourcing_lnum; ++gap->ga_len; @@ -4361,8 +4360,8 @@ static int uc_add_command(char_u *name, size_t name_len, char_u *rep, long argt, /* Extend the array unless we're replacing an existing command */ if (cmp != 0) { - if (ga_grow(gap, 1) != OK) - goto fail; + ga_grow(gap, 1); + if ((p = vim_strnsave(name, (int)name_len)) == NULL) goto fail; @@ -5868,7 +5867,8 @@ void alist_set(alist_T *al, int count, char_u **files, int use_curbuf, int *fnum int i; alist_clear(al); - if (ga_grow(&al->al_ga, count) == OK) { + ga_grow(&al->al_ga, count); + { for (i = 0; i < count; ++i) { if (got_int) { /* When adding many buffers this can take a long time. Allow @@ -5887,8 +5887,8 @@ void alist_set(alist_T *al, int count, char_u **files, int use_curbuf, int *fnum ui_breakcheck(); } vim_free(files); - } else - FreeWild(count, files); + } + if (al == &global_alist) arg_had_last = FALSE; } diff --git a/src/ex_getln.c b/src/ex_getln.c index 0cf9ff2dd8..f9332f1b31 100644 --- a/src/ex_getln.c +++ b/src/ex_getln.c @@ -1,4 +1,4 @@ -/* vi:set ts=8 sts=4 sw=4: +/* vi:set ts=2 sts=2 sw=2: * * VIM - Vi IMproved by Bram Moolenaar * @@ -1807,8 +1807,7 @@ getexmodeline ( */ got_int = FALSE; while (!got_int) { - if (ga_grow(&line_ga, 40) == FAIL) - break; + ga_grow(&line_ga, 40); /* Get one character at a time. Don't use inchar(), it can't handle * special characters. */ @@ -3999,9 +3998,8 @@ expand_shellcmd ( /* Expand matches in one directory of $PATH. */ ret = expand_wildcards(1, &buf, num_file, file, flags); if (ret == OK) { - if (ga_grow(&ga, *num_file) == FAIL) - FreeWild(*num_file, *file); - else { + ga_grow(&ga, *num_file); + { for (i = 0; i < *num_file; ++i) { s = (*file)[i]; if (STRLEN(s) > l) { @@ -4111,8 +4109,7 @@ static int ExpandUserDefined(expand_T *xp, regmatch_T *regmatch, int *num_file, continue; } - if (ga_grow(&ga, 1) == FAIL) - break; + ga_grow(&ga, 1); ((char_u **)ga.ga_data)[ga.ga_len] = vim_strnsave(s, (int)(e - s)); ++ga.ga_len; @@ -4146,8 +4143,7 @@ static int ExpandUserList(expand_T *xp, int *num_file, char_u ***file) if (li->li_tv.v_type != VAR_STRING || li->li_tv.vval.v_string == NULL) continue; /* Skip non-string items and empty strings */ - if (ga_grow(&ga, 1) == FAIL) - break; + ga_grow(&ga, 1); ((char_u **)ga.ga_data)[ga.ga_len] = vim_strsave(li->li_tv.vval.v_string); @@ -4195,8 +4191,7 @@ static int ExpandRTDir(char_u *pat, int *num_file, char_u ***file, char *dirname e = vim_strchr(s, '\n'); if (e == NULL) e = s + STRLEN(s); - if (ga_grow(&ga, 1) == FAIL) - break; + ga_grow(&ga, 1); if (e - 4 > s && STRNICMP(e - 4, ".vim", 4) == 0) { for (s = e - 4; s > matches; mb_ptr_back(matches, s)) if (*s == '\n' || vim_ispathsep(*s)) @@ -4263,15 +4258,15 @@ char_u *globpath(char_u *path, char_u *file, int expand_options) len += (int)STRLEN(p[i]) + 1; /* Concatenate new results to previous ones. */ - if (ga_grow(&ga, len) == OK) { - cur = (char_u *)ga.ga_data + ga.ga_len; - for (i = 0; i < num_p; ++i) { - STRCPY(cur, p[i]); - cur += STRLEN(p[i]); - *cur++ = '\n'; - } - ga.ga_len += len; + ga_grow(&ga, len); + cur = (char_u *)ga.ga_data + ga.ga_len; + for (i = 0; i < num_p; ++i) { + STRCPY(cur, p[i]); + cur += STRLEN(p[i]); + *cur++ = '\n'; } + ga.ga_len += len; + FreeWild(num_p, p); } } diff --git a/src/fileio.c b/src/fileio.c index 5bf75e34c4..7ae771c6b4 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -1,4 +1,4 @@ -/* vi:set ts=8 sts=4 sw=4: +/* vi:set ts=2 sts=2 sw=2: * * VIM - Vi IMproved by Bram Moolenaar * @@ -6216,8 +6216,9 @@ static int au_new_group(char_u *name) for (i = 0; i < augroups.ga_len; ++i) if (AUGROUP_NAME(i) == NULL) break; - if (i == augroups.ga_len && ga_grow(&augroups, 1) == FAIL) - return AUGROUP_ERROR; + if (i == augroups.ga_len) { + ga_grow(&augroups, 1); + } AUGROUP_NAME(i) = vim_strsave(name); if (AUGROUP_NAME(i) == NULL) diff --git a/src/fold.c b/src/fold.c index 8af2b891f4..f643f538a7 100644 --- a/src/fold.c +++ b/src/fold.c @@ -1,4 +1,4 @@ -/* vim:set ts=8 sts=4 sw=4: +/* vim:set ts=2 sts=2 sw=2: * vim600:fdm=marker fdl=1 fdc=3: * * VIM - Vi IMproved by Bram Moolenaar @@ -606,7 +606,8 @@ void foldCreate(linenr_T start, linenr_T end) } i = (int)(fp - (fold_T *)gap->ga_data); - if (ga_grow(gap, 1) == OK) { + ga_grow(gap, 1); + { fp = (fold_T *)gap->ga_data + i; ga_init(&fold_ga, (int)sizeof(fold_T), 10); @@ -614,7 +615,8 @@ void foldCreate(linenr_T start, linenr_T end) for (cont = 0; i + cont < gap->ga_len; ++cont) if (fp[cont].fd_top > end_rel) break; - if (cont > 0 && ga_grow(&fold_ga, cont) == OK) { + if (cont > 0) { + ga_grow(&fold_ga, cont); /* If the first fold starts before the new fold, let the new fold * start there. Otherwise the existing fold would change. */ if (start_rel > fp->fd_top) @@ -660,6 +662,7 @@ void foldCreate(linenr_T start, linenr_T end) } } + /* deleteFold() {{{2 */ /* * Delete a fold at line "start" in the current window. @@ -1001,8 +1004,6 @@ void foldAdjustCursor(void) /* cloneFoldGrowArray() {{{2 */ /* * Will "clone" (i.e deep copy) a garray_T of folds. - * - * Return FAIL if the operation cannot be completed, otherwise OK. */ void cloneFoldGrowArray(garray_T *from, garray_T *to) { @@ -1011,9 +1012,12 @@ void cloneFoldGrowArray(garray_T *from, garray_T *to) fold_T *to_p; ga_init(to, from->ga_itemsize, from->ga_growsize); - if (from->ga_len == 0 || ga_grow(to, from->ga_len) == FAIL) + + if (from->ga_len == 0) return; + ga_grow(to, from->ga_len); + from_p = (fold_T *)from->ga_data; to_p = (fold_T *)to->ga_data; @@ -1308,7 +1312,8 @@ static void deleteFoldEntry(garray_T *gap, int idx, int recursive) /* Move nested folds one level up, to overwrite the fold that is * deleted. */ moved = fp->fd_nested.ga_len; - if (ga_grow(gap, (int)(moved - 1)) == OK) { + ga_grow(gap, (int)(moved - 1)); + { /* Get "fp" again, the array may have been reallocated. */ fp = (fold_T *)gap->ga_data + idx; @@ -2509,8 +2514,8 @@ static int foldInsert(garray_T *gap, int i) { fold_T *fp; - if (ga_grow(gap, 1) != OK) - return FAIL; + ga_grow(gap, 1); + fp = (fold_T *)gap->ga_data + i; if (i < gap->ga_len) memmove(fp + 1, fp, sizeof(fold_T) * (gap->ga_len - i)); @@ -2552,7 +2557,8 @@ static void foldSplit(garray_T *gap, int i, linenr_T top, linenr_T bot) gap2 = &fp[1].fd_nested; (void)(foldFind(gap1, bot + 1 - fp->fd_top, &fp2)); len = (int)((fold_T *)gap1->ga_data + gap1->ga_len - fp2); - if (len > 0 && ga_grow(gap2, len) == OK) { + if (len > 0) { + ga_grow(gap2, len); for (idx = 0; idx < len; ++idx) { ((fold_T *)gap2->ga_data)[idx] = fp2[idx]; ((fold_T *)gap2->ga_data)[idx].fd_top @@ -2652,7 +2658,8 @@ static void foldMerge(fold_T *fp1, garray_T *gap, fold_T *fp2) foldMerge(fp3, gap2, fp4); /* Move nested folds in fp2 to the end of fp1. */ - if (gap2->ga_len > 0 && ga_grow(gap1, gap2->ga_len) == OK) { + if (gap2->ga_len > 0) { + ga_grow(gap1, gap2->ga_len); for (idx = 0; idx < gap2->ga_len; ++idx) { ((fold_T *)gap1->ga_data)[gap1->ga_len] = ((fold_T *)gap2->ga_data)[idx]; diff --git a/src/garray.c b/src/garray.c index 7dee7203cc..4084e572ad 100644 --- a/src/garray.c +++ b/src/garray.c @@ -55,9 +55,7 @@ void ga_init(garray_T *gap, int itemsize, int growsize) /// /// @param gap /// @param n -/// -/// @return FAIL for failure, OK otherwise. -int ga_grow(garray_T *gap, int n) +void ga_grow(garray_T *gap, int n) { size_t old_len; size_t new_len; @@ -72,15 +70,11 @@ int ga_grow(garray_T *gap, int n) ? alloc((unsigned)new_len) : xrealloc(gap->ga_data, new_len); - if (pp == NULL) { - return FAIL; - } old_len = gap->ga_itemsize * gap->ga_maxlen; memset(pp + old_len, 0, new_len - old_len); gap->ga_maxlen = gap->ga_len + n; gap->ga_data = pp; } - return OK; } /// Sort "gap" and remove duplicate entries. "gap" is expected to contain a @@ -140,10 +134,9 @@ char_u* ga_concat_strings(garray_T *gap) void ga_concat(garray_T *gap, char_u *s) { int len = (int)STRLEN(s); - if (ga_grow(gap, len) == OK) { - memmove((char *)gap->ga_data + gap->ga_len, s, (size_t)len); - gap->ga_len += len; - } + ga_grow(gap, len); + memmove((char *)gap->ga_data + gap->ga_len, s, (size_t)len); + gap->ga_len += len; } /// Append one byte to a growarray which contains bytes. @@ -152,10 +145,9 @@ void ga_concat(garray_T *gap, char_u *s) /// @param c void ga_append(garray_T *gap, int c) { - if (ga_grow(gap, 1) == OK) { - *((char *) gap->ga_data + gap->ga_len) = c; - ++gap->ga_len; - } + ga_grow(gap, 1); + *((char *) gap->ga_data + gap->ga_len) = c; + ++gap->ga_len; } #if defined(UNIX) || defined(WIN3264) diff --git a/src/garray.h b/src/garray.h index a5736a54b3..163ee92aef 100644 --- a/src/garray.h +++ b/src/garray.h @@ -17,7 +17,7 @@ typedef struct growarray { void ga_clear(garray_T *gap); void ga_clear_strings(garray_T *gap); void ga_init(garray_T *gap, int itemsize, int growsize); -int ga_grow(garray_T *gap, int n); +void ga_grow(garray_T *gap, int n); char_u *ga_concat_strings(garray_T *gap); void ga_remove_duplicate_strings(garray_T *gap); void ga_concat(garray_T *gap, char_u *s); diff --git a/src/main.c b/src/main.c index 38967eed35..14dd89e26d 100644 --- a/src/main.c +++ b/src/main.c @@ -1426,8 +1426,8 @@ scripterror: /* Add the file to the global argument list. */ - if (ga_grow(&global_alist.al_ga, 1) == FAIL - || (p = vim_strsave((char_u *)argv[0])) == NULL) + ga_grow(&global_alist.al_ga, 1); + if ((p = vim_strsave((char_u *)argv[0])) == NULL) mch_exit(2); if (parmp->diff_mode && os_isdir(p) && GARGCOUNT > 0 && !os_isdir(alist_name(&GARGLIST[0]))) { diff --git a/src/menu.c b/src/menu.c index dd66faa4f9..70508fe560 100644 --- a/src/menu.c +++ b/src/menu.c @@ -1512,26 +1512,25 @@ void ex_menutranslate(exarg_T *eap) if (arg == to) EMSG(_(e_invarg)); else { - if (ga_grow(&menutrans_ga, 1) == OK) { - tp = (menutrans_T *)menutrans_ga.ga_data; - from = vim_strsave(from); - if (from != NULL) { - from_noamp = menu_text(from, NULL, NULL); - to = vim_strnsave(to, (int)(arg - to)); - if (from_noamp != NULL && to != NULL) { - menu_translate_tab_and_shift(from); - menu_translate_tab_and_shift(to); - menu_unescape_name(from); - menu_unescape_name(to); - tp[menutrans_ga.ga_len].from = from; - tp[menutrans_ga.ga_len].from_noamp = from_noamp; - tp[menutrans_ga.ga_len].to = to; - ++menutrans_ga.ga_len; - } else { - vim_free(from); - vim_free(from_noamp); - vim_free(to); - } + ga_grow(&menutrans_ga, 1); + tp = (menutrans_T *)menutrans_ga.ga_data; + from = vim_strsave(from); + if (from != NULL) { + from_noamp = menu_text(from, NULL, NULL); + to = vim_strnsave(to, (int)(arg - to)); + if (from_noamp != NULL && to != NULL) { + menu_translate_tab_and_shift(from); + menu_translate_tab_and_shift(to); + menu_unescape_name(from); + menu_unescape_name(to); + tp[menutrans_ga.ga_len].from = from; + tp[menutrans_ga.ga_len].from_noamp = from_noamp; + tp[menutrans_ga.ga_len].to = to; + ++menutrans_ga.ga_len; + } else { + vim_free(from); + vim_free(from_noamp); + vim_free(to); } } } diff --git a/src/message.c b/src/message.c index 5ec87c6297..f3bac7179d 100644 --- a/src/message.c +++ b/src/message.c @@ -2293,26 +2293,25 @@ void mch_errmsg(char *str) error_ga.ga_growsize = 80; error_ga.ga_itemsize = 1; } - if (ga_grow(&error_ga, len) == OK) { - memmove((char_u *)error_ga.ga_data + error_ga.ga_len, - (char_u *)str, len); + ga_grow(&error_ga, len); + memmove((char_u *)error_ga.ga_data + error_ga.ga_len, + (char_u *)str, len); #ifdef UNIX - /* remove CR characters, they are displayed */ - { - char_u *p; - - p = (char_u *)error_ga.ga_data + error_ga.ga_len; - for (;; ) { - p = vim_strchr(p, '\r'); - if (p == NULL) - break; - *p = ' '; - } + /* remove CR characters, they are displayed */ + { + char_u *p; + + p = (char_u *)error_ga.ga_data + error_ga.ga_len; + for (;; ) { + p = vim_strchr(p, '\r'); + if (p == NULL) + break; + *p = ' '; } -#endif - --len; /* don't count the NUL at the end */ - error_ga.ga_len += len; } +#endif + --len; /* don't count the NUL at the end */ + error_ga.ga_len += len; } /* diff --git a/src/option.c b/src/option.c index d52117e83b..529f676886 100644 --- a/src/option.c +++ b/src/option.c @@ -2001,14 +2001,13 @@ void set_init_1(void) if (p != NULL && *p != NUL) { /* First time count the NUL, otherwise count the ','. */ len = (int)STRLEN(p) + 3; - if (ga_grow(&ga, len) == OK) { - if (ga.ga_len > 0) - STRCAT(ga.ga_data, ","); - STRCAT(ga.ga_data, p); - add_pathsep(ga.ga_data); - STRCAT(ga.ga_data, "*"); - ga.ga_len += len; - } + ga_grow(&ga, len); + if (ga.ga_len > 0) + STRCAT(ga.ga_data, ","); + STRCAT(ga.ga_data, p); + add_pathsep(ga.ga_data); + STRCAT(ga.ga_data, "*"); + ga.ga_len += len; } if (mustfree) vim_free(p); @@ -7653,8 +7652,7 @@ static void langmap_set_entry(int from, int to) b = i; } - if (ga_grow(&langmap_mapga, 1) != OK) - return; /* out of memory */ + ga_grow(&langmap_mapga, 1); /* insert new entry at position "a" */ entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a; diff --git a/src/os/users.c b/src/os/users.c index 5972e3f1e8..e7b362637b 100644 --- a/src/os/users.c +++ b/src/os/users.c @@ -26,9 +26,7 @@ int os_get_usernames(garray_T *users) while ((pw = getpwent()) != NULL) { // pw->pw_name shouldn't be NULL but just in case... if (pw->pw_name != NULL) { - if (ga_grow(users, 1) == FAIL) { - return FAIL; - } + ga_grow(users, 1); user = (char *)vim_strsave((char_u*)pw->pw_name); if (user == NULL) { return FAIL; diff --git a/src/path.c b/src/path.c index 49ac84506f..d2b52ee93e 100644 --- a/src/path.c +++ b/src/path.c @@ -665,9 +665,7 @@ static void expand_path_option(char_u *curdir, garray_T *gap) simplify_filename(buf); } - if (ga_grow(gap, 1) == FAIL) - break; - + ga_grow(gap, 1); p = vim_strsave(buf); if (p == NULL) @@ -1231,8 +1229,7 @@ addfile ( return; /* Make room for another item in the file list. */ - if (ga_grow(gap, 1) == FAIL) - return; + ga_grow(gap, 1); p = alloc((unsigned)(STRLEN(f) + 1 + isdir)); diff --git a/src/regexp.c b/src/regexp.c index 44e25856ce..289e64cf2c 100644 --- a/src/regexp.c +++ b/src/regexp.c @@ -4285,14 +4285,11 @@ regmatch ( break; if (i == backpos.ga_len) { /* First time at this BACK, make room to store the pos. */ - if (ga_grow(&backpos, 1) == FAIL) - status = RA_FAIL; - else { - /* get "ga_data" again, it may have changed */ - bp = (backpos_T *)backpos.ga_data; - bp[i].bp_scan = scan; - ++backpos.ga_len; - } + 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; } else if (reg_save_equal(&bp[i].bp_pos)) /* Still at same position as last time, fail. */ status = RA_NOMATCH; @@ -4632,9 +4629,8 @@ regmatch ( if ((long)((unsigned)regstack.ga_len >> 10) >= p_mmp) { EMSG(_(e_maxmempat)); status = RA_FAIL; - } else if (ga_grow(®stack, sizeof(regstar_T)) == FAIL) - status = RA_FAIL; - else { + } else { + ga_grow(®stack, sizeof(regstar_T)); regstack.ga_len += sizeof(regstar_T); rp = regstack_push(rst.minval <= rst.maxval ? RS_STAR_LONG : RS_STAR_SHORT, scan); @@ -4671,9 +4667,8 @@ regmatch ( if ((long)((unsigned)regstack.ga_len >> 10) >= p_mmp) { EMSG(_(e_maxmempat)); status = RA_FAIL; - } else if (ga_grow(®stack, sizeof(regbehind_T)) == FAIL) - status = RA_FAIL; - else { + } else { + ga_grow(®stack, sizeof(regbehind_T)); regstack.ga_len += sizeof(regbehind_T); rp = regstack_push(RS_BEHIND1, scan); if (rp == NULL) @@ -5094,8 +5089,7 @@ static regitem_T *regstack_push(regstate_T state, char_u *scan) EMSG(_(e_maxmempat)); return NULL; } - if (ga_grow(®stack, sizeof(regitem_T)) == FAIL) - return NULL; + ga_grow(®stack, sizeof(regitem_T)); rp = (regitem_T *)((char *)regstack.ga_data + regstack.ga_len); rp->rs_state = state; diff --git a/src/spell.c b/src/spell.c index 134b5464b6..60e1fb172c 100644 --- a/src/spell.c +++ b/src/spell.c @@ -1,4 +1,4 @@ -/* vi:set ts=8 sts=4 sw=4: +/* vi:set ts=2 sts=2 sw=2: * * VIM - Vi IMproved by Bram Moolenaar * @@ -2899,8 +2899,7 @@ static int read_rep_section(FILE *fd, garray_T *gap, short *first) if (cnt < 0) return SP_TRUNCERROR; - if (ga_grow(gap, cnt) == FAIL) - return SP_OTHERERROR; + ga_grow(gap, cnt); /* <rep> : <repfromlen> <repfrom> <reptolen> <repto> */ for (; gap->ga_len < cnt; ++gap->ga_len) { @@ -2960,8 +2959,7 @@ static int read_sal_section(FILE *fd, slang_T *slang) gap = &slang->sl_sal; ga_init(gap, sizeof(salitem_T), 10); - if (ga_grow(gap, cnt + 1) == FAIL) - return SP_OTHERERROR; + ga_grow(gap, cnt + 1); /* <sal> : <salfromlen> <salfrom> <saltolen> <salto> */ for (; gap->ga_len < cnt; ++gap->ga_len) { @@ -3259,15 +3257,15 @@ static int read_compound(FILE *fd, slang_T *slang, int len) c = get2c(fd); /* <comppatcount> */ todo -= 2; ga_init(gap, sizeof(char_u *), c); - if (ga_grow(gap, c) == OK) - while (--c >= 0) { - ((char_u **)(gap->ga_data))[gap->ga_len++] = - read_cnt_string(fd, 1, &cnt); - /* <comppatlen> <comppattext> */ - if (cnt < 0) - return cnt; - todo -= cnt + 1; - } + ga_grow(gap, c); + while (--c >= 0) { + ((char_u **)(gap->ga_data))[gap->ga_len++] = + read_cnt_string(fd, 1, &cnt); + /* <comppatlen> <comppattext> */ + if (cnt < 0) + return cnt; + todo -= cnt + 1; + } } if (todo < 0) return SP_FORMERROR; @@ -3419,8 +3417,7 @@ static int init_syl_tab(slang_T *slang) l = (int)(p - s); if (l >= SY_MAXLEN) return SP_FORMERROR; - if (ga_grow(&slang->sl_syl_items, 1) == FAIL) - return SP_OTHERERROR; + ga_grow(&slang->sl_syl_items, 1); syl = ((syl_item_T *)slang->sl_syl_items.ga_data) + slang->sl_syl_items.ga_len++; vim_strncpy(syl->sy_chars, s, l); @@ -3502,8 +3499,7 @@ static int set_sofo(slang_T *lp, char_u *from, char_u *to) * sl_sal_first[] is used for latin1 "from" characters. */ gap = &lp->sl_sal; ga_init(gap, sizeof(int *), 1); - if (ga_grow(gap, 256) == FAIL) - return SP_OTHERERROR; + ga_grow(gap, 256); memset(gap->ga_data, 0, sizeof(int *) * 256); gap->ga_len = 256; @@ -3929,11 +3925,7 @@ char_u *did_set_spelllang(win_T *wp) } if (region_mask != 0) { - if (ga_grow(&ga, 1) == FAIL) { - ga_clear(&ga); - ret_msg = e_outofmem; - goto theend; - } + ga_grow(&ga, 1); LANGP_ENTRY(ga, ga.ga_len)->lp_slang = slang; LANGP_ENTRY(ga, ga.ga_len)->lp_region = region_mask; ++ga.ga_len; @@ -3993,7 +3985,8 @@ char_u *did_set_spelllang(win_T *wp) if (slang != NULL && nobreak) slang->sl_nobreak = TRUE; } - if (slang != NULL && ga_grow(&ga, 1) == OK) { + if (slang != NULL) { + ga_grow(&ga, 1); region_mask = REGION_ALL; if (use_region != NULL && !dont_use_region) { /* find region in sl_regions */ @@ -5014,7 +5007,8 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) && STRCMP(((char_u **)(gap->ga_data))[i + 1], items[2]) == 0) break; - if (i >= gap->ga_len && ga_grow(gap, 2) == OK) { + if (i >= gap->ga_len) { + ga_grow(gap, 2); ((char_u **)(gap->ga_data))[gap->ga_len++] = getroom_save(spin, items[1]); ((char_u **)(gap->ga_data))[gap->ga_len++] @@ -5245,7 +5239,8 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) if (str_equal(p, aff_entry->ae_cond)) break; } - if (idx < 0 && ga_grow(&spin->si_prefcond, 1) == OK) { + if (idx < 0) { + ga_grow(&spin->si_prefcond, 1); /* Not found, add a new condition. */ idx = spin->si_prefcond.ga_len++; pp = ((char_u **)spin->si_prefcond.ga_data) @@ -5753,14 +5748,13 @@ static void add_fromto(spellinfo_T *spin, garray_T *gap, char_u *from, char_u *t fromto_T *ftp; char_u word[MAXWLEN]; - if (ga_grow(gap, 1) == OK) { - ftp = ((fromto_T *)gap->ga_data) + gap->ga_len; - (void)spell_casefold(from, (int)STRLEN(from), word, MAXWLEN); - ftp->ft_from = getroom_save(spin, word); - (void)spell_casefold(to, (int)STRLEN(to), word, MAXWLEN); - ftp->ft_to = getroom_save(spin, word); - ++gap->ga_len; - } + ga_grow(gap, 1); + ftp = ((fromto_T *)gap->ga_data) + gap->ga_len; + (void)spell_casefold(from, (int)STRLEN(from), word, MAXWLEN); + ftp->ft_from = getroom_save(spin, word); + (void)spell_casefold(to, (int)STRLEN(to), word, MAXWLEN); + ftp->ft_to = getroom_save(spin, word); + ++gap->ga_len; } /* @@ -7865,8 +7859,7 @@ sug_filltable ( gap->ga_len = 0; prev_nr = 0; for (np = p; np != NULL && np->wn_byte == NUL; np = np->wn_sibling) { - if (ga_grow(gap, 10) == FAIL) - return -1; + ga_grow(gap, 10); nr = (np->wn_flags << 16) + (np->wn_region & 0xffff); /* Compute the offset from the previous nr and store the @@ -9367,18 +9360,17 @@ spell_suggest_list ( /* Make room in "gap". */ ga_init(gap, sizeof(char_u *), sug.su_ga.ga_len + 1); - if (ga_grow(gap, sug.su_ga.ga_len) == OK) { - for (i = 0; i < sug.su_ga.ga_len; ++i) { - stp = &SUG(sug.su_ga, i); + ga_grow(gap, sug.su_ga.ga_len); + for (i = 0; i < sug.su_ga.ga_len; ++i) { + stp = &SUG(sug.su_ga, i); - /* The suggested word may replace only part of "word", add the not - * replaced part. */ - wcopy = alloc(stp->st_wordlen - + (unsigned)STRLEN(sug.su_badptr + stp->st_orglen) + 1); - STRCPY(wcopy, stp->st_word); - STRCPY(wcopy + stp->st_wordlen, sug.su_badptr + stp->st_orglen); - ((char_u **)gap->ga_data)[gap->ga_len++] = wcopy; - } + /* The suggested word may replace only part of "word", add the not + * replaced part. */ + wcopy = alloc(stp->st_wordlen + + (unsigned)STRLEN(sug.su_badptr + stp->st_orglen) + 1); + STRCPY(wcopy, stp->st_word); + STRCPY(wcopy + stp->st_wordlen, sug.su_badptr + stp->st_orglen); + ((char_u **)gap->ga_data)[gap->ga_len++] = wcopy; } spell_find_cleanup(&sug); @@ -9779,8 +9771,10 @@ someerror: ga.ga_len = 0; for (;; ) { c = getc(fd); /* <sugline> */ - if (c < 0 || ga_grow(&ga, 1) == FAIL) + if (c < 0) { goto someerror; + } + ga_grow(&ga, 1); ((char_u *)ga.ga_data)[ga.ga_len++] = c; if (c == NUL) break; @@ -11494,8 +11488,7 @@ static void score_comp_sal(suginfo_T *su) int score; int lpi; - if (ga_grow(&su->su_sga, su->su_ga.ga_len) == FAIL) - return; + ga_grow(&su->su_sga, su->su_ga.ga_len); /* Use the sound-folding of the first language that supports it. */ for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) { @@ -11594,8 +11587,7 @@ static void score_combine(suginfo_T *su) (void)cleanup_suggestions(&su->su_sga, su->su_maxscore, su->su_maxcount); ga_init(&ga, (int)sizeof(suginfo_T), 1); - if (ga_grow(&ga, su->su_ga.ga_len + su->su_sga.ga_len) == FAIL) - return; + ga_grow(&ga, su->su_ga.ga_len + su->su_sga.ga_len); stp = &SUG(ga, 0); for (i = 0; i < su->su_ga.ga_len || i < su->su_sga.ga_len; ++i) { @@ -12248,7 +12240,8 @@ add_suggestion ( } } - if (i < 0 && ga_grow(gap, 1) == OK) { + if (i < 0) { + ga_grow(gap, 1); /* Add a suggestion. */ stp = &SUG(*gap, gap->ga_len); stp->st_word = vim_strnsave(goodword, goodlen); diff --git a/src/syntax.c b/src/syntax.c index 31e72a23d1..0985cea98b 100644 --- a/src/syntax.c +++ b/src/syntax.c @@ -1,4 +1,4 @@ -/* vi:set ts=8 sts=4 sw=4: +/* vi:set ts=2 sts=2 sw=2: * * VIM - Vi IMproved by Bram Moolenaar * @@ -1388,10 +1388,8 @@ static synstate_T *store_current_state(void) /* Need to clear it, might be something remaining from when the * length was less than SST_FIX_STATES. */ ga_init(&sp->sst_union.sst_ga, (int)sizeof(bufstate_T), 1); - if (ga_grow(&sp->sst_union.sst_ga, current_state.ga_len) == FAIL) - sp->sst_stacksize = 0; - else - sp->sst_union.sst_ga.ga_len = current_state.ga_len; + ga_grow(&sp->sst_union.sst_ga, current_state.ga_len); + sp->sst_union.sst_ga.ga_len = current_state.ga_len; bp = SYN_STATE_P(&(sp->sst_union.sst_ga)); } else bp = sp->sst_union.sst_stack; @@ -1422,8 +1420,8 @@ static void load_current_state(synstate_T *from) clear_current_state(); validate_current_state(); keepend_level = -1; - if (from->sst_stacksize - && ga_grow(¤t_state, from->sst_stacksize) != FAIL) { + if (from->sst_stacksize) { + ga_grow(¤t_state, from->sst_stacksize); if (from->sst_stacksize > SST_FIX_STATES) bp = SYN_STATE_P(&(from->sst_union.sst_ga)); else @@ -2060,10 +2058,9 @@ syn_current_attr ( /* Add the index to a list, so that we can check * later that we don't match it again (and cause an * endless loop). */ - if (ga_grow(&zero_width_next_ga, 1) == OK) { - ((int *)(zero_width_next_ga.ga_data)) - [zero_width_next_ga.ga_len++] = next_match_idx; - } + ga_grow(&zero_width_next_ga, 1); + ((int *)(zero_width_next_ga.ga_data)) + [zero_width_next_ga.ga_len++] = next_match_idx; next_match_idx = -1; } else cur_si = push_next_match(cur_si); @@ -2584,8 +2581,7 @@ update_si_end ( */ static int push_current_state(int idx) { - if (ga_grow(¤t_state, 1) == FAIL) - return FAIL; + ga_grow(¤t_state, 1); memset(&CUR_STATE(current_state.ga_len), 0, sizeof(stateitem_T)); CUR_STATE(current_state.ga_len).si_idx = idx; ++current_state.ga_len; @@ -4387,39 +4383,40 @@ syn_cmd_match ( eap->nextcmd = check_nextcmd(rest); if (!ends_excmd(*rest) || eap->skip) rest = NULL; - else if (ga_grow(&curwin->w_s->b_syn_patterns, 1) != FAIL - && (syn_id = syn_check_group(arg, - (int)(group_name_end - arg))) != 0) { - syn_incl_toplevel(syn_id, &syn_opt_arg.flags); - /* - * Store the pattern in the syn_items list - */ - idx = curwin->w_s->b_syn_patterns.ga_len; - SYN_ITEMS(curwin->w_s)[idx] = item; - SYN_ITEMS(curwin->w_s)[idx].sp_syncing = syncing; - SYN_ITEMS(curwin->w_s)[idx].sp_type = SPTYPE_MATCH; - SYN_ITEMS(curwin->w_s)[idx].sp_syn.id = syn_id; - SYN_ITEMS(curwin->w_s)[idx].sp_syn.inc_tag = current_syn_inc_tag; - SYN_ITEMS(curwin->w_s)[idx].sp_flags = syn_opt_arg.flags; - SYN_ITEMS(curwin->w_s)[idx].sp_sync_idx = sync_idx; - SYN_ITEMS(curwin->w_s)[idx].sp_cont_list = syn_opt_arg.cont_list; - SYN_ITEMS(curwin->w_s)[idx].sp_syn.cont_in_list = - syn_opt_arg.cont_in_list; - SYN_ITEMS(curwin->w_s)[idx].sp_cchar = conceal_char; - if (syn_opt_arg.cont_in_list != NULL) - curwin->w_s->b_syn_containedin = TRUE; - SYN_ITEMS(curwin->w_s)[idx].sp_next_list = syn_opt_arg.next_list; - ++curwin->w_s->b_syn_patterns.ga_len; - - /* remember that we found a match for syncing on */ - if (syn_opt_arg.flags & (HL_SYNC_HERE|HL_SYNC_THERE)) - curwin->w_s->b_syn_sync_flags |= SF_MATCH; - if (syn_opt_arg.flags & HL_FOLD) - ++curwin->w_s->b_syn_folditems; - - redraw_curbuf_later(SOME_VALID); - syn_stack_free_all(curwin->w_s); /* Need to recompute all syntax. */ - return; /* don't free the progs and patterns now */ + else { + ga_grow(&curwin->w_s->b_syn_patterns, 1); + if ((syn_id = syn_check_group(arg, (int)(group_name_end - arg))) != 0) { + syn_incl_toplevel(syn_id, &syn_opt_arg.flags); + /* + * Store the pattern in the syn_items list + */ + idx = curwin->w_s->b_syn_patterns.ga_len; + SYN_ITEMS(curwin->w_s)[idx] = item; + SYN_ITEMS(curwin->w_s)[idx].sp_syncing = syncing; + SYN_ITEMS(curwin->w_s)[idx].sp_type = SPTYPE_MATCH; + SYN_ITEMS(curwin->w_s)[idx].sp_syn.id = syn_id; + SYN_ITEMS(curwin->w_s)[idx].sp_syn.inc_tag = current_syn_inc_tag; + SYN_ITEMS(curwin->w_s)[idx].sp_flags = syn_opt_arg.flags; + SYN_ITEMS(curwin->w_s)[idx].sp_sync_idx = sync_idx; + SYN_ITEMS(curwin->w_s)[idx].sp_cont_list = syn_opt_arg.cont_list; + SYN_ITEMS(curwin->w_s)[idx].sp_syn.cont_in_list = + syn_opt_arg.cont_in_list; + SYN_ITEMS(curwin->w_s)[idx].sp_cchar = conceal_char; + if (syn_opt_arg.cont_in_list != NULL) + curwin->w_s->b_syn_containedin = TRUE; + SYN_ITEMS(curwin->w_s)[idx].sp_next_list = syn_opt_arg.next_list; + ++curwin->w_s->b_syn_patterns.ga_len; + + /* remember that we found a match for syncing on */ + if (syn_opt_arg.flags & (HL_SYNC_HERE|HL_SYNC_THERE)) + curwin->w_s->b_syn_sync_flags |= SF_MATCH; + if (syn_opt_arg.flags & HL_FOLD) + ++curwin->w_s->b_syn_folditems; + + redraw_curbuf_later(SOME_VALID); + syn_stack_free_all(curwin->w_s); /* Need to recompute all syntax. */ + return; /* don't free the progs and patterns now */ + } } } @@ -4598,48 +4595,49 @@ syn_cmd_region ( eap->nextcmd = check_nextcmd(rest); if (!ends_excmd(*rest) || eap->skip) rest = NULL; - else if (ga_grow(&(curwin->w_s->b_syn_patterns), pat_count) != FAIL - && (syn_id = syn_check_group(arg, - (int)(group_name_end - arg))) != 0) { - syn_incl_toplevel(syn_id, &syn_opt_arg.flags); - /* - * Store the start/skip/end in the syn_items list - */ - idx = curwin->w_s->b_syn_patterns.ga_len; - for (item = ITEM_START; item <= ITEM_END; ++item) { - for (ppp = pat_ptrs[item]; ppp != NULL; ppp = ppp->pp_next) { - SYN_ITEMS(curwin->w_s)[idx] = *(ppp->pp_synp); - SYN_ITEMS(curwin->w_s)[idx].sp_syncing = syncing; - SYN_ITEMS(curwin->w_s)[idx].sp_type = - (item == ITEM_START) ? SPTYPE_START : - (item == ITEM_SKIP) ? SPTYPE_SKIP : SPTYPE_END; - SYN_ITEMS(curwin->w_s)[idx].sp_flags |= syn_opt_arg.flags; - SYN_ITEMS(curwin->w_s)[idx].sp_syn.id = syn_id; - SYN_ITEMS(curwin->w_s)[idx].sp_syn.inc_tag = - current_syn_inc_tag; - SYN_ITEMS(curwin->w_s)[idx].sp_syn_match_id = - ppp->pp_matchgroup_id; - SYN_ITEMS(curwin->w_s)[idx].sp_cchar = conceal_char; - if (item == ITEM_START) { - SYN_ITEMS(curwin->w_s)[idx].sp_cont_list = - syn_opt_arg.cont_list; - SYN_ITEMS(curwin->w_s)[idx].sp_syn.cont_in_list = - syn_opt_arg.cont_in_list; - if (syn_opt_arg.cont_in_list != NULL) - curwin->w_s->b_syn_containedin = TRUE; - SYN_ITEMS(curwin->w_s)[idx].sp_next_list = - syn_opt_arg.next_list; + else { + ga_grow(&(curwin->w_s->b_syn_patterns), pat_count); + if ((syn_id = syn_check_group(arg, (int)(group_name_end - arg))) != 0) { + syn_incl_toplevel(syn_id, &syn_opt_arg.flags); + /* + * Store the start/skip/end in the syn_items list + */ + idx = curwin->w_s->b_syn_patterns.ga_len; + for (item = ITEM_START; item <= ITEM_END; ++item) { + for (ppp = pat_ptrs[item]; ppp != NULL; ppp = ppp->pp_next) { + SYN_ITEMS(curwin->w_s)[idx] = *(ppp->pp_synp); + SYN_ITEMS(curwin->w_s)[idx].sp_syncing = syncing; + SYN_ITEMS(curwin->w_s)[idx].sp_type = + (item == ITEM_START) ? SPTYPE_START : + (item == ITEM_SKIP) ? SPTYPE_SKIP : SPTYPE_END; + SYN_ITEMS(curwin->w_s)[idx].sp_flags |= syn_opt_arg.flags; + SYN_ITEMS(curwin->w_s)[idx].sp_syn.id = syn_id; + SYN_ITEMS(curwin->w_s)[idx].sp_syn.inc_tag = + current_syn_inc_tag; + SYN_ITEMS(curwin->w_s)[idx].sp_syn_match_id = + ppp->pp_matchgroup_id; + SYN_ITEMS(curwin->w_s)[idx].sp_cchar = conceal_char; + if (item == ITEM_START) { + SYN_ITEMS(curwin->w_s)[idx].sp_cont_list = + syn_opt_arg.cont_list; + SYN_ITEMS(curwin->w_s)[idx].sp_syn.cont_in_list = + syn_opt_arg.cont_in_list; + if (syn_opt_arg.cont_in_list != NULL) + curwin->w_s->b_syn_containedin = TRUE; + SYN_ITEMS(curwin->w_s)[idx].sp_next_list = + syn_opt_arg.next_list; + } + ++curwin->w_s->b_syn_patterns.ga_len; + ++idx; + if (syn_opt_arg.flags & HL_FOLD) + ++curwin->w_s->b_syn_folditems; } - ++curwin->w_s->b_syn_patterns.ga_len; - ++idx; - if (syn_opt_arg.flags & HL_FOLD) - ++curwin->w_s->b_syn_folditems; } - } - redraw_curbuf_later(SOME_VALID); - syn_stack_free_all(curwin->w_s); /* Need to recompute all syntax. */ - success = TRUE; /* don't free the progs and patterns now */ + redraw_curbuf_later(SOME_VALID); + syn_stack_free_all(curwin->w_s); /* Need to recompute all syntax. */ + success = TRUE; /* don't free the progs and patterns now */ + } } } @@ -4880,10 +4878,7 @@ static int syn_add_cluster(char_u *name) /* * Make room for at least one other cluster entry. */ - if (ga_grow(&curwin->w_s->b_syn_clusters, 1) == FAIL) { - vim_free(name); - return 0; - } + ga_grow(&curwin->w_s->b_syn_clusters, 1); memset(&(SYN_CLSTR(curwin->w_s)[len]), 0, sizeof(syn_cluster_T)); SYN_CLSTR(curwin->w_s)[len].scl_name = name; @@ -6898,7 +6893,7 @@ static garray_T cterm_attr_table = {0, 0, 0, 0, NULL}; * Return the attr number for a set of colors and font. * Add a new entry to the term_attr_table, cterm_attr_table or gui_attr_table * if the combination is new. - * Return 0 for error (no more room). + * Return 0 for error. */ static int get_attr_entry(garray_T *table, attrentry_T *aep) { @@ -6965,8 +6960,7 @@ static int get_attr_entry(garray_T *table, attrentry_T *aep) /* * This is a new combination of colors and font, add an entry. */ - if (ga_grow(table, 1) == FAIL) - return 0; + ga_grow(table, 1); taep = &(((attrentry_T *)table->ga_data)[table->ga_len]); memset(taep, 0, sizeof(attrentry_T)); @@ -7513,10 +7507,7 @@ static int syn_add_group(char_u *name) /* * Make room for at least one other syntax_highlight entry. */ - if (ga_grow(&highlight_ga, 1) == FAIL) { - vim_free(name); - return 0; - } + ga_grow(&highlight_ga, 1); memset(&(HL_TABLE()[highlight_ga.ga_len]), 0, sizeof(struct hl_group)); HL_TABLE()[highlight_ga.ga_len].sg_name = name; @@ -7696,8 +7687,7 @@ int highlight_changed(void) * Temporarily utilize 10 more hl entries. Have to be in there * simultaneously in case of table overflows in get_attr_entry() */ - if (ga_grow(&highlight_ga, 10) == FAIL) - return FAIL; + ga_grow(&highlight_ga, 10); hlcnt = highlight_ga.ga_len; if (id_S == 0) { /* Make sure id_S is always valid to simplify code below */ memset(&HL_TABLE()[hlcnt + 9], 0, sizeof(struct hl_group)); @@ -1812,7 +1812,8 @@ parse_line: * Store the info we need later, which depends on the kind of * tags we are dealing with. */ - if (ga_grow(&ga_match[mtt], 1) == OK) { + ga_grow(&ga_match[mtt], 1); + { int len; if (help_only) { @@ -1922,10 +1923,6 @@ parse_line: } else vim_free(mfp); } - } else { /* Out of memory! Just forget about the rest. */ - retval = OK; - stop_searching = TRUE; - break; } } if (use_cscope && eof) @@ -2035,9 +2032,8 @@ static void found_tagfile_cb(char_u *fname, void *cookie); */ static void found_tagfile_cb(char_u *fname, void *cookie) { - if (ga_grow(&tag_fnames, 1) == OK) - ((char_u **)(tag_fnames.ga_data))[tag_fnames.ga_len++] = - vim_strsave(fname); + ga_grow(&tag_fnames, 1); + ((char_u **)(tag_fnames.ga_data))[tag_fnames.ga_len++] = vim_strsave(fname); } #if defined(EXITFREE) || defined(PROTO) diff --git a/src/undo.c b/src/undo.c index 454d59fbfc..f4e95c43f7 100644 --- a/src/undo.c +++ b/src/undo.c @@ -1,4 +1,4 @@ -/* vi:set ts=8 sts=4 sw=4: +/* vi:set ts=2 sts=2 sw=2: * * VIM - Vi IMproved by Bram Moolenaar * @@ -2383,8 +2383,7 @@ void ex_undolist(exarg_T *eap) while (uhp != NULL) { if (uhp->uh_prev.ptr == NULL && uhp->uh_walk != nomark && uhp->uh_walk != mark) { - if (ga_grow(&ga, 1) == FAIL) - break; + ga_grow(&ga, 1); vim_snprintf((char *)IObuff, IOSIZE, "%6ld %7ld ", uhp->uh_seq, changes); u_add_time(IObuff + STRLEN(IObuff), IOSIZE - STRLEN(IObuff), diff --git a/src/window.c b/src/window.c index f8927acb8b..56882bc17d 100644 --- a/src/window.c +++ b/src/window.c @@ -1,4 +1,4 @@ -/* vi:set ts=8 sts=4 sw=4: +/* vi:set ts=2 sts=2 sw=2: * * VIM - Vi IMproved by Bram Moolenaar * @@ -3866,12 +3866,12 @@ void win_size_save(garray_T *gap) win_T *wp; ga_init(gap, (int)sizeof(int), 1); - if (ga_grow(gap, win_count() * 2) == OK) - for (wp = firstwin; wp != NULL; wp = wp->w_next) { - ((int *)gap->ga_data)[gap->ga_len++] = - wp->w_width + wp->w_vsep_width; - ((int *)gap->ga_data)[gap->ga_len++] = wp->w_height; - } + ga_grow(gap, win_count() * 2); + for (wp = firstwin; wp != NULL; wp = wp->w_next) { + ((int *)gap->ga_data)[gap->ga_len++] = + wp->w_width + wp->w_vsep_width; + ((int *)gap->ga_data)[gap->ga_len++] = wp->w_height; + } } /* |