Call to list_append_string cannot fail.

Clean up the use of list_append_string and remove error checks.
This commit is contained in:
oni-link 2014-04-25 01:54:26 +02:00 committed by Thiago de Arruda
parent 8d5a546d3f
commit 38ac85da87
2 changed files with 25 additions and 30 deletions

View File

@ -5550,23 +5550,21 @@ void list_append_dict(list_T *list, dict_T *dict)
/* /*
* Make a copy of "str" and append it as an item to list "l". * Make a copy of "str" and append it as an item to list "l".
* When "len" >= 0 use "str[len]". * When "len" >= 0 use "str[len]".
* Returns FAIL when out of memory.
*/ */
int list_append_string(list_T *l, char_u *str, int len) void list_append_string(list_T *l, char_u *str, int len)
{ {
listitem_T *li = listitem_alloc(); listitem_T *li = listitem_alloc();
if (li == NULL)
return FAIL;
list_append(l, li); list_append(l, li);
li->li_tv.v_type = VAR_STRING; li->li_tv.v_type = VAR_STRING;
li->li_tv.v_lock = 0; li->li_tv.v_lock = 0;
if (str == NULL)
if (str == NULL) {
li->li_tv.vval.v_string = NULL; li->li_tv.vval.v_string = NULL;
else if ((li->li_tv.vval.v_string = (len >= 0 ? vim_strnsave(str, len) } else {
: vim_strsave(str))) == NULL) li->li_tv.vval.v_string = (len >= 0) ? vim_strnsave(str, len)
return FAIL; : vim_strsave(str);
return OK; }
} }
/* /*
@ -9432,10 +9430,10 @@ static void get_buffer_lines(buf_T *buf, linenr_T start, linenr_T end, int retli
start = 1; start = 1;
if (end > buf->b_ml.ml_line_count) if (end > buf->b_ml.ml_line_count)
end = buf->b_ml.ml_line_count; end = buf->b_ml.ml_line_count;
while (start <= end) while (start <= end) {
if (list_append_string(rettv->vval.v_list, list_append_string(
ml_get_buf(buf, start++, FALSE), -1) == FAIL) rettv->vval.v_list, ml_get_buf(buf, start++, FALSE), -1);
break; }
} }
} }
@ -11566,14 +11564,12 @@ static void find_some_match(typval_T *argvars, typval_T *rettv, int type)
/* return list with matched string and submatches */ /* return list with matched string and submatches */
for (i = 0; i < NSUBEXP; ++i) { for (i = 0; i < NSUBEXP; ++i) {
if (regmatch.endp[i] == NULL) { if (regmatch.endp[i] == NULL) {
if (list_append_string(rettv->vval.v_list, list_append_string(rettv->vval.v_list, (char_u *)"", 0);
(char_u *)"", 0) == FAIL) } else {
break; list_append_string(rettv->vval.v_list,
} else if (list_append_string(rettv->vval.v_list, regmatch.startp[i],
regmatch.startp[i], (int)(regmatch.endp[i] - regmatch.startp[i]));
(int)(regmatch.endp[i] - regmatch.startp[i])) }
== FAIL)
break;
} }
} else if (type == 2) { } else if (type == 2) {
/* return matched string */ /* return matched string */
@ -14120,9 +14116,7 @@ static void f_split(typval_T *argvars, typval_T *rettv)
if (keepempty || end > str || (rettv->vval.v_list->lv_len > 0 if (keepempty || end > str || (rettv->vval.v_list->lv_len > 0
&& *str != NUL && match && end < && *str != NUL && match && end <
regmatch.endp[0])) { regmatch.endp[0])) {
if (list_append_string(rettv->vval.v_list, str, list_append_string(rettv->vval.v_list, str, (int)(end - str));
(int)(end - str)) == FAIL)
break;
} }
if (!match) if (!match)
break; break;
@ -14859,7 +14853,6 @@ static void f_tagfiles(typval_T *argvars, typval_T *rettv)
{ {
char_u *fname; char_u *fname;
tagname_T tn; tagname_T tn;
int first;
if (rettv_list_alloc(rettv) == FAIL) if (rettv_list_alloc(rettv) == FAIL)
return; return;
@ -14867,10 +14860,12 @@ static void f_tagfiles(typval_T *argvars, typval_T *rettv)
if (fname == NULL) if (fname == NULL)
return; return;
for (first = TRUE;; first = FALSE) int first = TRUE;
if (get_tagfname(&tn, first, fname) == FAIL while (get_tagfname(&tn, first, fname) == OK) {
|| list_append_string(rettv->vval.v_list, fname, -1) == FAIL) list_append_string(rettv->vval.v_list, fname, -1);
break; first = FALSE;
}
tagname_free(&tn); tagname_free(&tn);
vim_free(fname); vim_free(fname);
} }

View File

@ -65,7 +65,7 @@ char_u *list_find_str(list_T *l, long idx);
void list_append(list_T *l, listitem_T *item); void list_append(list_T *l, listitem_T *item);
int list_append_tv(list_T *l, typval_T *tv); int list_append_tv(list_T *l, typval_T *tv);
void list_append_dict(list_T *list, dict_T *dict); void list_append_dict(list_T *list, dict_T *dict);
int list_append_string(list_T *l, char_u *str, int len); void list_append_string(list_T *l, char_u *str, int len);
int list_insert_tv(list_T *l, typval_T *tv, listitem_T *item); int list_insert_tv(list_T *l, typval_T *tv, listitem_T *item);
void list_remove(list_T *l, listitem_T *item, listitem_T *item2); void list_remove(list_T *l, listitem_T *item, listitem_T *item2);
void list_insert(list_T *l, listitem_T *ni, listitem_T *item); void list_insert(list_T *l, listitem_T *ni, listitem_T *item);