Replace alloc() with xmalloc() and remove immediate OOM checks

This commit is contained in:
Felipe Oliveira Carvalho
2014-05-09 03:30:26 -03:00
parent a80d7e86c1
commit 21784aeb00
42 changed files with 413 additions and 640 deletions

View File

@@ -501,7 +501,7 @@ open_line (
}
if (lead_len) {
/* allocate buffer (may concatenate p_extra later) */
leader = alloc(lead_len + lead_repl_len + extra_space + extra_len
leader = xmalloc(lead_len + lead_repl_len + extra_space + extra_len
+ (second_line_indent > 0 ? second_line_indent : 0) + 1);
allocated = leader; /* remember to free it later */
@@ -1702,9 +1702,7 @@ del_bytes (
if (was_alloced)
newp = oldp; /* use same allocated memory */
else { /* need to allocate a new line */
newp = alloc((unsigned)(oldlen + 1 - count));
if (newp == NULL)
return FAIL;
newp = xmalloc(oldlen + 1 - count);
memmove(newp, oldp, (size_t)col);
}
memmove(newp + col, oldp + col + count, (size_t)movelen);
@@ -2395,7 +2393,7 @@ int get_keystroke(void)
* bytes. */
maxlen = (buflen - 6 - len) / 3;
if (buf == NULL)
buf = alloc(buflen);
buf = xmalloc(buflen);
else if (maxlen < 10) {
/* Need some more space. This might happen when receiving a long
* escape sequence. */
@@ -2715,9 +2713,7 @@ char_u *expand_env_save(char_u *src)
*/
char_u *expand_env_save_opt(char_u *src, int one)
{
char_u *p;
p = alloc(MAXPATHL);
char_u *p = xmalloc(MAXPATHL);
expand_env_esc(src, p, MAXPATHL, FALSE, one, NULL);
return p;
}
@@ -2865,8 +2861,9 @@ expand_env_esc (
if (p_ssl && var != NULL && vim_strchr(var, '\\') != NULL) {
char_u *p = vim_strsave(var);
if (mustfree)
if (mustfree) {
free(var);
}
var = p;
mustfree = TRUE;
forward_slash(var);
@@ -3321,13 +3318,12 @@ home_replace_save (
)
{
char_u *dst;
unsigned len;
len = 3; /* space for "~/" and trailing NUL */
size_t len = 3; /* space for "~/" and trailing NUL */
if (src != NULL) /* just in case */
len += (unsigned)STRLEN(src);
dst = alloc(len);
home_replace(buf, src, dst, len, TRUE);
len += STRLEN(src);
dst = xmalloc(len);
home_replace(buf, src, dst, (int)len, TRUE);
return dst;
}
@@ -3488,7 +3484,7 @@ get_cmd_output (
len = ftell(fd); /* get size of temp file */
fseek(fd, 0L, SEEK_SET);
buffer = alloc(len + 1);
buffer = xmalloc(len + 1);
i = (int)fread((char *)buffer, (size_t)1, (size_t)len, fd);
fclose(fd);
os_remove((char *)tempname);