mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
No OOM error in call_shell() and read_string()
This commit is contained in:
parent
28b03dd190
commit
e76d146029
30
src/misc2.c
30
src/misc2.c
@ -1234,19 +1234,17 @@ int call_shell(char_u *cmd, ShellOpts opts, char_u *extra_shell_arg)
|
|||||||
if (ecmd == NULL)
|
if (ecmd == NULL)
|
||||||
ecmd = cmd;
|
ecmd = cmd;
|
||||||
}
|
}
|
||||||
ncmd = alloc((unsigned)(STRLEN(ecmd) + STRLEN(p_sxq) * 2 + 1));
|
ncmd = xmalloc(STRLEN(ecmd) + STRLEN(p_sxq) * 2 + 1);
|
||||||
if (ncmd != NULL) {
|
STRCPY(ncmd, p_sxq);
|
||||||
STRCPY(ncmd, p_sxq);
|
STRCAT(ncmd, ecmd);
|
||||||
STRCAT(ncmd, ecmd);
|
/* When 'shellxquote' is ( append ).
|
||||||
/* When 'shellxquote' is ( append ).
|
* When 'shellxquote' is "( append )". */
|
||||||
* When 'shellxquote' is "( append )". */
|
STRCAT(ncmd, STRCMP(p_sxq, "(") == 0 ? (char_u *)")"
|
||||||
STRCAT(ncmd, STRCMP(p_sxq, "(") == 0 ? (char_u *)")"
|
: STRCMP(p_sxq, "\"(") == 0 ? (char_u *)")\""
|
||||||
: STRCMP(p_sxq, "\"(") == 0 ? (char_u *)")\""
|
: p_sxq);
|
||||||
: p_sxq);
|
retval = os_call_shell(ncmd, opts, extra_shell_arg);
|
||||||
retval = os_call_shell(ncmd, opts, extra_shell_arg);
|
vim_free(ncmd);
|
||||||
vim_free(ncmd);
|
|
||||||
} else
|
|
||||||
retval = -1;
|
|
||||||
if (ecmd != cmd)
|
if (ecmd != cmd)
|
||||||
vim_free(ecmd);
|
vim_free(ecmd);
|
||||||
}
|
}
|
||||||
@ -1432,16 +1430,14 @@ time_t get8ctime(FILE *fd)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Read a string of length "cnt" from "fd" into allocated memory.
|
* 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 *read_string(FILE *fd, int cnt)
|
||||||
{
|
{
|
||||||
char_u *str;
|
|
||||||
int i;
|
int i;
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
/* allocate memory */
|
char_u *str = xmallocz(cnt);
|
||||||
str = alloc((unsigned)cnt + 1);
|
|
||||||
/* Read the string. Quit when running into the EOF. */
|
/* Read the string. Quit when running into the EOF. */
|
||||||
for (i = 0; i < cnt; ++i) {
|
for (i = 0; i < cnt; ++i) {
|
||||||
c = getc(fd);
|
c = getc(fd);
|
||||||
|
Loading…
Reference in New Issue
Block a user