passing-by: mark non-null return; remove invalid OOM check.

remove some #ifdef noise
This commit is contained in:
Justin M. Keyes
2015-03-04 18:57:43 -05:00
parent e4975f82c9
commit 86ee88163e
2 changed files with 11 additions and 42 deletions

View File

@@ -824,7 +824,7 @@ void ml_recover(void)
(void)recover_names(fname, FALSE, i, &fname_used); (void)recover_names(fname, FALSE, i, &fname_used);
} }
if (fname_used == NULL) if (fname_used == NULL)
goto theend; /* out of memory */ goto theend; // user chose invalid number.
/* When called from main() still need to initialize storage structure */ /* When called from main() still need to initialize storage structure */
if (called_from_main && ml_open(curbuf) == FAIL) if (called_from_main && ml_open(curbuf) == FAIL)
@@ -1321,37 +1321,27 @@ recover_names (
if (dir_name[0] == '.' && dir_name[1] == NUL) { /* check current dir */ if (dir_name[0] == '.' && dir_name[1] == NUL) { /* check current dir */
if (fname == NULL) { if (fname == NULL) {
names[0] = vim_strsave((char_u *)"*.sw?"); names[0] = vim_strsave((char_u *)"*.sw?");
#if defined(UNIX) || defined(WIN3264)
/* For Unix names starting with a dot are special. MS-Windows /* For Unix names starting with a dot are special. MS-Windows
* supports this too, on some file systems. */ * supports this too, on some file systems. */
names[1] = vim_strsave((char_u *)".*.sw?"); names[1] = vim_strsave((char_u *)".*.sw?");
names[2] = vim_strsave((char_u *)".sw?"); names[2] = vim_strsave((char_u *)".sw?");
num_names = 3; num_names = 3;
#else
num_names = 1;
#endif
} else } else
num_names = recov_file_names(names, fname_res, TRUE); num_names = recov_file_names(names, fname_res, TRUE);
} else { /* check directory dir_name */ } else { /* check directory dir_name */
if (fname == NULL) { if (fname == NULL) {
names[0] = concat_fnames(dir_name, (char_u *)"*.sw?", TRUE); names[0] = concat_fnames(dir_name, (char_u *)"*.sw?", TRUE);
#if defined(UNIX) || defined(WIN3264)
/* For Unix names starting with a dot are special. MS-Windows /* For Unix names starting with a dot are special. MS-Windows
* supports this too, on some file systems. */ * supports this too, on some file systems. */
names[1] = concat_fnames(dir_name, (char_u *)".*.sw?", TRUE); names[1] = concat_fnames(dir_name, (char_u *)".*.sw?", TRUE);
names[2] = concat_fnames(dir_name, (char_u *)".sw?", TRUE); names[2] = concat_fnames(dir_name, (char_u *)".sw?", TRUE);
num_names = 3; num_names = 3;
#else
num_names = 1;
#endif
} else { } else {
#if defined(UNIX) || defined(WIN3264)
p = dir_name + STRLEN(dir_name); p = dir_name + STRLEN(dir_name);
if (after_pathsep(dir_name, p) && p[-1] == p[-2]) { if (after_pathsep(dir_name, p) && p[-1] == p[-2]) {
/* Ends with '//', Use Full path for swap name */ /* Ends with '//', Use Full path for swap name */
tail = make_percent_swname(dir_name, fname_res); tail = make_percent_swname(dir_name, fname_res);
} else } else
#endif
tail = path_tail(fname_res); tail = path_tail(fname_res);
tail = concat_fnames(dir_name, tail, TRUE); tail = concat_fnames(dir_name, tail, TRUE);
num_names = recov_file_names(names, tail, FALSE); num_names = recov_file_names(names, tail, FALSE);
@@ -1359,15 +1349,6 @@ recover_names (
} }
} }
// check for out-of-memory
for (int i = 0; i < num_names; ++i) {
if (names[i] == NULL) {
for (int j = 0; j < num_names; ++j)
free(names[j]);
num_names = 0;
break;
}
}
if (num_names == 0) if (num_names == 0)
num_files = 0; num_files = 0;
else if (expand_wildcards(num_names, names, &num_files, &files, else if (expand_wildcards(num_names, names, &num_files, &files,
@@ -1453,7 +1434,6 @@ recover_names (
return file_count; return file_count;
} }
#if defined(UNIX) || defined(WIN3264) /* Need _very_ long file names */
/* /*
* Append the full path to name with path separators made into percent * Append the full path to name with path separators made into percent
* signs, to dir. An unnamed buffer is handled as "" (<currentdir>/"") * signs, to dir. An unnamed buffer is handled as "" (<currentdir>/"")
@@ -1475,7 +1455,6 @@ static char_u *make_percent_swname(char_u *dir, char_u *name)
} }
return d; return d;
} }
#endif
#ifdef UNIX #ifdef UNIX
static int process_still_running; static int process_still_running;
@@ -1576,17 +1555,12 @@ static time_t swapfile_info(char_u *fname)
} }
static int recov_file_names(char_u **names, char_u *path, int prepend_dot) static int recov_file_names(char_u **names, char_u *path, int prepend_dot)
FUNC_ATTR_NONNULL_ALL
{ {
int num_names; int num_names = 0;
char_u *p;
int i;
num_names = 0; // May also add the file name with a dot prepended, for swap file in same
// dir as original file.
/*
* May also add the file name with a dot prepended, for swap file in same
* dir as original file.
*/
if (prepend_dot) { if (prepend_dot) {
names[num_names] = modname(path, (char_u *)".sw?", TRUE); names[num_names] = modname(path, (char_u *)".sw?", TRUE);
if (names[num_names] == NULL) if (names[num_names] == NULL)
@@ -1597,8 +1571,8 @@ static int recov_file_names(char_u **names, char_u *path, int prepend_dot)
// Form the normal swap file name pattern by appending ".sw?". // Form the normal swap file name pattern by appending ".sw?".
names[num_names] = concat_fnames(path, (char_u *)".sw?", FALSE); names[num_names] = concat_fnames(path, (char_u *)".sw?", FALSE);
if (num_names >= 1) { /* check if we have the same name twice */ if (num_names >= 1) { /* check if we have the same name twice */
p = names[num_names - 1]; char_u *p = names[num_names - 1];
i = (int)STRLEN(names[num_names - 1]) - (int)STRLEN(names[num_names]); int i = (int)STRLEN(names[num_names - 1]) - (int)STRLEN(names[num_names]);
if (i > 0) if (i > 0)
p += i; /* file name has been expanded to full path */ p += i; /* file name has been expanded to full path */
@@ -3088,7 +3062,6 @@ char_u *makeswapname(char_u *fname, char_u *ffname, buf_T *buf, char_u *dir_name
char_u fname_buf[MAXPATHL]; char_u fname_buf[MAXPATHL];
#endif #endif
#if defined(UNIX) || defined(WIN3264) /* Need _very_ long file names */
s = dir_name + STRLEN(dir_name); s = dir_name + STRLEN(dir_name);
if (after_pathsep(dir_name, s) && s[-1] == s[-2]) { /* Ends with '//', Use Full path */ if (after_pathsep(dir_name, s) && s[-1] == s[-2]) { /* Ends with '//', Use Full path */
r = NULL; r = NULL;
@@ -3098,7 +3071,6 @@ char_u *makeswapname(char_u *fname, char_u *ffname, buf_T *buf, char_u *dir_name
} }
return r; return r;
} }
#endif
#ifdef HAVE_READLINK #ifdef HAVE_READLINK
/* Expand symlink in the file name, so that we put the swap file with the /* Expand symlink in the file name, so that we put the swap file with the

View File

@@ -83,15 +83,12 @@ FileComparison path_full_compare(char_u *s1, char_u *s2, int checkname)
return kDifferentFiles; return kDifferentFiles;
} }
/// Get the tail of a path: the file name. /// Gets the tail (i.e., the filename segment) of a path `fname`.
/// ///
/// @param fname A file path. /// @return pointer just past the last path separator (empty string, if fname
/// @return /// ends in a slash), or empty string if fname is NULL.
/// - Empty string, if fname is NULL.
/// - The position of the last path separator + 1. (i.e. empty string, if
/// fname ends in a slash).
/// - Never NULL.
char_u *path_tail(char_u *fname) char_u *path_tail(char_u *fname)
FUNC_ATTR_NONNULL_RET
{ {
if (fname == NULL) { if (fname == NULL) {
return (char_u *)""; return (char_u *)"";