aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelipe Oliveira Carvalho <felipekde@gmail.com>2014-04-21 19:36:36 -0300
committerThiago de Arruda <tpadilha84@gmail.com>2014-04-24 10:31:31 -0300
commite76d146029b988fe6f6eeb5df9d2c4328c07e3c0 (patch)
tree508a8c3aa2c0dfda40d18a52882f39439ca9ef35
parent28b03dd19037cdf1b15dd1050f39465be87e7195 (diff)
downloadrneovim-e76d146029b988fe6f6eeb5df9d2c4328c07e3c0.tar.gz
rneovim-e76d146029b988fe6f6eeb5df9d2c4328c07e3c0.tar.bz2
rneovim-e76d146029b988fe6f6eeb5df9d2c4328c07e3c0.zip
No OOM error in call_shell() and read_string()
-rw-r--r--src/misc2.c30
1 files changed, 13 insertions, 17 deletions
diff --git a/src/misc2.c b/src/misc2.c
index a5a9393bcf..34d1cadd6c 100644
--- a/src/misc2.c
+++ b/src/misc2.c
@@ -1234,19 +1234,17 @@ int call_shell(char_u *cmd, ShellOpts opts, char_u *extra_shell_arg)
if (ecmd == NULL)
ecmd = cmd;
}
- ncmd = alloc((unsigned)(STRLEN(ecmd) + STRLEN(p_sxq) * 2 + 1));
- if (ncmd != NULL) {
- STRCPY(ncmd, p_sxq);
- STRCAT(ncmd, ecmd);
- /* When 'shellxquote' is ( append ).
- * When 'shellxquote' is "( append )". */
- STRCAT(ncmd, STRCMP(p_sxq, "(") == 0 ? (char_u *)")"
- : STRCMP(p_sxq, "\"(") == 0 ? (char_u *)")\""
- : p_sxq);
- retval = os_call_shell(ncmd, opts, extra_shell_arg);
- vim_free(ncmd);
- } else
- retval = -1;
+ ncmd = xmalloc(STRLEN(ecmd) + STRLEN(p_sxq) * 2 + 1);
+ STRCPY(ncmd, p_sxq);
+ STRCAT(ncmd, ecmd);
+ /* When 'shellxquote' is ( append ).
+ * When 'shellxquote' is "( append )". */
+ STRCAT(ncmd, STRCMP(p_sxq, "(") == 0 ? (char_u *)")"
+ : STRCMP(p_sxq, "\"(") == 0 ? (char_u *)")\""
+ : p_sxq);
+ retval = os_call_shell(ncmd, opts, extra_shell_arg);
+ vim_free(ncmd);
+
if (ecmd != cmd)
vim_free(ecmd);
}
@@ -1432,16 +1430,14 @@ time_t get8ctime(FILE *fd)
/*
* Read a string of length "cnt" from "fd" into allocated memory.
- * Returns NULL when out of memory or unable to read that many bytes.
+ * Returns NULL when unable to read that many bytes.
*/
char_u *read_string(FILE *fd, int cnt)
{
- char_u *str;
int i;
int c;
- /* allocate memory */
- str = alloc((unsigned)cnt + 1);
+ char_u *str = xmallocz(cnt);
/* Read the string. Quit when running into the EOF. */
for (i = 0; i < cnt; ++i) {
c = getc(fd);