From 13848aadbfed94a62505d4e349426990c75d2ae5 Mon Sep 17 00:00:00 2001 From: Felipe Oliveira Carvalho Date: Tue, 1 Apr 2014 01:41:39 -0300 Subject: 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. --- src/diff.c | 51 +++++++++++++++++++++++---------------------------- 1 file changed, 23 insertions(+), 28 deletions(-) (limited to 'src/diff.c') diff --git a/src/diff.c b/src/diff.c index 0db4890cfe..eb1325b76e 100644 --- a/src/diff.c +++ b/src/diff.c @@ -825,31 +825,29 @@ static void diff_file(char_u *tmp_orig, char_u *tmp_new, char_u *tmp_diff) + STRLEN(p_srr) + 27; char_u *cmd = alloc((unsigned)len); - if (cmd != NULL) { - /* We don't want $DIFF_OPTIONS to get in the way. */ - if (os_getenv("DIFF_OPTIONS")) { - vim_setenv((char_u *)"DIFF_OPTIONS", (char_u *)""); - } - - /* Build the diff command and execute it. Always use -a, binary - * differences are of no use. Ignore errors, diff returns - * non-zero when differences have been found. */ - vim_snprintf((char *)cmd, len, "diff %s%s%s%s%s %s", - diff_a_works == FALSE ? "" : "-a ", - "", - (diff_flags & DIFF_IWHITE) ? "-b " : "", - (diff_flags & DIFF_ICASE) ? "-i " : "", - tmp_orig, tmp_new); - append_redir(cmd, (int)len, p_srr, tmp_diff); - block_autocmds(); /* Avoid ShellCmdPost stuff */ - (void)call_shell( - cmd, - kShellOptFilter | kShellOptSilent | kShellOptDoOut, - NULL - ); - unblock_autocmds(); - vim_free(cmd); - } + /* We don't want $DIFF_OPTIONS to get in the way. */ + if (os_getenv("DIFF_OPTIONS")) { + vim_setenv((char_u *)"DIFF_OPTIONS", (char_u *)""); + } + + /* Build the diff command and execute it. Always use -a, binary + * differences are of no use. Ignore errors, diff returns + * non-zero when differences have been found. */ + vim_snprintf((char *)cmd, len, "diff %s%s%s%s%s %s", + diff_a_works == FALSE ? "" : "-a ", + "", + (diff_flags & DIFF_IWHITE) ? "-b " : "", + (diff_flags & DIFF_ICASE) ? "-i " : "", + tmp_orig, tmp_new); + append_redir(cmd, (int)len, p_srr, tmp_diff); + block_autocmds(); /* Avoid ShellCmdPost stuff */ + (void)call_shell( + cmd, + kShellOptFilter | kShellOptSilent | kShellOptDoOut, + NULL + ); + unblock_autocmds(); + vim_free(cmd); } } @@ -902,9 +900,6 @@ void ex_diffpatch(exarg_T *eap) #endif // ifdef UNIX buf = alloc((unsigned)buflen); - if (buf == NULL) { - goto theend; - } #ifdef UNIX -- cgit