mirror of
https://github.com/neovim/neovim.git
synced 2025-09-29 06:28:35 +00:00
Remove simpler cases of OOM error handling (after *alloc calls)
By simpler cases I mean cases where the OOM error is not expected to be handled by the caller of the function that calls `alloc`, `lalloc`, `xrealloc`, `xmalloc`, `alloc_clear`, and `lalloc_clear`. These are the functions that: - Do not return an allocated buffer - Have OOM as the only error condition I took note of the functions that expect the caller to handle the OOM error and will go through them to check all the callers that may be handling OOM error in future commits. I'm ignoring eval.c and ex_.c in this series of commits. eval.c will soon be obsolete and I will deal with ex_.c in later PRs.
This commit is contained in:

committed by
Thiago de Arruda

parent
6bbffee0a5
commit
13848aadbf
113
src/misc2.c
113
src/misc2.c
@@ -233,9 +233,6 @@ coladvance2 (
|
||||
char_u *newline = alloc(idx + correct + 1);
|
||||
int t;
|
||||
|
||||
if (newline == NULL)
|
||||
return FAIL;
|
||||
|
||||
for (t = 0; t < idx; ++t)
|
||||
newline[t] = line[t];
|
||||
|
||||
@@ -260,8 +257,6 @@ coladvance2 (
|
||||
return FAIL;
|
||||
|
||||
newline = alloc(linelen + csize);
|
||||
if (newline == NULL)
|
||||
return FAIL;
|
||||
|
||||
for (t = 0; t < linelen; t++) {
|
||||
if (t != idx)
|
||||
@@ -623,10 +618,8 @@ char_u *vim_strnsave(char_u *string, int len)
|
||||
char_u *p;
|
||||
|
||||
p = alloc((unsigned)(len + 1));
|
||||
if (p != NULL) {
|
||||
STRNCPY(p, string, len);
|
||||
p[len] = NUL;
|
||||
}
|
||||
STRNCPY(p, string, len);
|
||||
p[len] = NUL;
|
||||
return p;
|
||||
}
|
||||
|
||||
@@ -668,21 +661,20 @@ char_u *vim_strsave_escaped_ext(char_u *string, char_u *esc_chars, int cc, int b
|
||||
++length; /* count an ordinary char */
|
||||
}
|
||||
escaped_string = alloc(length);
|
||||
if (escaped_string != NULL) {
|
||||
p2 = escaped_string;
|
||||
for (p = string; *p; p++) {
|
||||
if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1) {
|
||||
memmove(p2, p, (size_t)l);
|
||||
p2 += l;
|
||||
p += l - 1; /* skip multibyte char */
|
||||
continue;
|
||||
}
|
||||
if (vim_strchr(esc_chars, *p) != NULL || (bsl && rem_backslash(p)))
|
||||
*p2++ = cc;
|
||||
*p2++ = *p;
|
||||
p2 = escaped_string;
|
||||
for (p = string; *p; p++) {
|
||||
if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1) {
|
||||
memmove(p2, p, (size_t)l);
|
||||
p2 += l;
|
||||
p += l - 1; /* skip multibyte char */
|
||||
continue;
|
||||
}
|
||||
*p2 = NUL;
|
||||
if (vim_strchr(esc_chars, *p) != NULL || (bsl && rem_backslash(p)))
|
||||
*p2++ = cc;
|
||||
*p2++ = *p;
|
||||
}
|
||||
*p2 = NUL;
|
||||
|
||||
return escaped_string;
|
||||
}
|
||||
|
||||
@@ -736,43 +728,41 @@ char_u *vim_strsave_shellescape(char_u *string, int do_special)
|
||||
|
||||
/* Allocate memory for the result and fill it. */
|
||||
escaped_string = alloc(length);
|
||||
if (escaped_string != NULL) {
|
||||
d = escaped_string;
|
||||
d = escaped_string;
|
||||
|
||||
/* add opening quote */
|
||||
*d++ = '\'';
|
||||
/* add opening quote */
|
||||
*d++ = '\'';
|
||||
|
||||
for (p = string; *p != NUL; ) {
|
||||
if (*p == '\'') {
|
||||
*d++ = '\'';
|
||||
for (p = string; *p != NUL; ) {
|
||||
if (*p == '\'') {
|
||||
*d++ = '\'';
|
||||
*d++ = '\\';
|
||||
*d++ = '\'';
|
||||
*d++ = '\'';
|
||||
++p;
|
||||
continue;
|
||||
}
|
||||
if (*p == '\n' || (*p == '!' && (csh_like || do_special))) {
|
||||
*d++ = '\\';
|
||||
if (csh_like && do_special)
|
||||
*d++ = '\\';
|
||||
*d++ = '\'';
|
||||
*d++ = '\'';
|
||||
++p;
|
||||
continue;
|
||||
}
|
||||
if (*p == '\n' || (*p == '!' && (csh_like || do_special))) {
|
||||
*d++ = '\\';
|
||||
if (csh_like && do_special)
|
||||
*d++ = '\\';
|
||||
*d++ = *p++;
|
||||
continue;
|
||||
}
|
||||
if (do_special && find_cmdline_var(p, &l) >= 0) {
|
||||
*d++ = '\\'; /* insert backslash */
|
||||
while (--l >= 0) /* copy the var */
|
||||
*d++ = *p++;
|
||||
continue;
|
||||
}
|
||||
if (do_special && find_cmdline_var(p, &l) >= 0) {
|
||||
*d++ = '\\'; /* insert backslash */
|
||||
while (--l >= 0) /* copy the var */
|
||||
*d++ = *p++;
|
||||
continue;
|
||||
}
|
||||
|
||||
MB_COPY_CHAR(p, d);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* add terminating quote and finish with a NUL */
|
||||
*d++ = '\'';
|
||||
*d = NUL;
|
||||
MB_COPY_CHAR(p, d);
|
||||
}
|
||||
|
||||
/* add terminating quote and finish with a NUL */
|
||||
*d++ = '\'';
|
||||
*d = NUL;
|
||||
|
||||
return escaped_string;
|
||||
}
|
||||
|
||||
@@ -847,8 +837,6 @@ char_u *strup_save(char_u *orig)
|
||||
newl = utf_char2len(uc);
|
||||
if (newl != l) {
|
||||
s = alloc((unsigned)STRLEN(res) + 1 + newl - l);
|
||||
if (s == NULL)
|
||||
break;
|
||||
memmove(s, res, p - res);
|
||||
STRCPY(s + (p - res) + newl, p + l);
|
||||
p = s + (p - res);
|
||||
@@ -1452,18 +1440,17 @@ char_u *read_string(FILE *fd, int cnt)
|
||||
|
||||
/* allocate memory */
|
||||
str = alloc((unsigned)cnt + 1);
|
||||
if (str != NULL) {
|
||||
/* Read the string. Quit when running into the EOF. */
|
||||
for (i = 0; i < cnt; ++i) {
|
||||
c = getc(fd);
|
||||
if (c == EOF) {
|
||||
vim_free(str);
|
||||
return NULL;
|
||||
}
|
||||
str[i] = c;
|
||||
/* Read the string. Quit when running into the EOF. */
|
||||
for (i = 0; i < cnt; ++i) {
|
||||
c = getc(fd);
|
||||
if (c == EOF) {
|
||||
vim_free(str);
|
||||
return NULL;
|
||||
}
|
||||
str[i] = NUL;
|
||||
str[i] = c;
|
||||
}
|
||||
str[i] = NUL;
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user