aboutsummaryrefslogtreecommitdiff
path: root/src/file_search.c
diff options
context:
space:
mode:
authorFelipe Oliveira Carvalho <felipekde@gmail.com>2014-04-01 01:41:39 -0300
committerThiago de Arruda <tpadilha84@gmail.com>2014-04-06 22:54:59 -0300
commit13848aadbfed94a62505d4e349426990c75d2ae5 (patch)
tree664873759b05c4e50e879ef7630621dc023d3b56 /src/file_search.c
parent6bbffee0a5b4239e3177812c5f5f20133aa60fe8 (diff)
downloadrneovim-13848aadbfed94a62505d4e349426990c75d2ae5.tar.gz
rneovim-13848aadbfed94a62505d4e349426990c75d2ae5.tar.bz2
rneovim-13848aadbfed94a62505d4e349426990c75d2ae5.zip
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.
Diffstat (limited to 'src/file_search.c')
-rw-r--r--src/file_search.c51
1 files changed, 19 insertions, 32 deletions
diff --git a/src/file_search.c b/src/file_search.c
index 28193b63c7..d4a3e35094 100644
--- a/src/file_search.c
+++ b/src/file_search.c
@@ -390,11 +390,7 @@ vim_findfile_init (
helper = walker;
ptr = xrealloc(search_ctx->ffsc_stopdirs_v,
(dircount + 1) * sizeof(char_u *));
- if (ptr)
- search_ctx->ffsc_stopdirs_v = ptr;
- else
- /* ignore, keep what we have and continue */
- break;
+ search_ctx->ffsc_stopdirs_v = ptr;
walker = vim_strchr(walker, ';');
if (walker) {
search_ctx->ffsc_stopdirs_v[dircount-1] =
@@ -789,9 +785,7 @@ char_u *vim_findfile(void *search_ctx_arg)
if (path_with_url(dirptrs[0])) {
stackp->ffs_filearray = (char_u **)
alloc((unsigned)sizeof(char *));
- if (stackp->ffs_filearray != NULL
- && (stackp->ffs_filearray[0]
- = vim_strsave(dirptrs[0])) != NULL)
+ if ((stackp->ffs_filearray[0] = vim_strsave(dirptrs[0])) != NULL)
stackp->ffs_filearray_size = 1;
else
stackp->ffs_filearray_size = 0;
@@ -1136,10 +1130,6 @@ static int ff_wc_equal(char_u *s1, char_u *s2)
* maintains the list of already visited files and dirs
* returns FAIL if the given file/dir is already in the list
* returns OK if it is newly added
- *
- * TODO: What to do on memory allocation problems?
- * -> return TRUE - Better the file is found several times instead of
- * never.
*/
static int ff_check_visited(ff_visited_T **visited_list, char_u *fname, char_u *wc_path)
{
@@ -1189,29 +1179,27 @@ static int ff_check_visited(ff_visited_T **visited_list, char_u *fname, char_u *
vp = (ff_visited_T *)alloc((unsigned)(sizeof(ff_visited_T)
+ STRLEN(ff_expand_buffer)));
- if (vp != NULL) {
#ifdef UNIX
- if (!url) {
- vp->ffv_dev_valid = TRUE;
- vp->ffv_ino = st.st_ino;
- vp->ffv_dev = st.st_dev;
- vp->ffv_fname[0] = NUL;
- } else {
- vp->ffv_dev_valid = FALSE;
- STRCPY(vp->ffv_fname, ff_expand_buffer);
- }
-#else
+ if (!url) {
+ vp->ffv_dev_valid = TRUE;
+ vp->ffv_ino = st.st_ino;
+ vp->ffv_dev = st.st_dev;
+ vp->ffv_fname[0] = NUL;
+ } else {
+ vp->ffv_dev_valid = FALSE;
STRCPY(vp->ffv_fname, ff_expand_buffer);
+ }
+#else
+ STRCPY(vp->ffv_fname, ff_expand_buffer);
#endif
- if (wc_path != NULL)
- vp->ffv_wc_path = vim_strsave(wc_path);
- else
- vp->ffv_wc_path = NULL;
+ if (wc_path != NULL)
+ vp->ffv_wc_path = vim_strsave(wc_path);
+ else
+ vp->ffv_wc_path = NULL;
- vp->ffv_next = *visited_list;
- *visited_list = vp;
- }
+ vp->ffv_next = *visited_list;
+ *visited_list = vp;
return OK;
}
@@ -1563,8 +1551,7 @@ find_file_in_path_option (
break;
}
- if ((buf = alloc((int)(MAXPATHL))) == NULL)
- break;
+ buf = alloc((int)(MAXPATHL));
/* copy next path */
buf[0] = 0;