aboutsummaryrefslogtreecommitdiff
path: root/src/fileio.c
diff options
context:
space:
mode:
authorFelipe Oliveira Carvalho <felipekde@gmail.com>2014-04-18 01:01:04 -0300
committerThiago de Arruda <tpadilha84@gmail.com>2014-04-24 10:31:31 -0300
commit1befc494144fbf1d5bff6d7eaeeae4bc20d75f54 (patch)
treef12641aebdff2700df1262f5bc1c00bea07d88b7 /src/fileio.c
parent471da2de810964052d4d2ab5ba0e23446ea7880d (diff)
downloadrneovim-1befc494144fbf1d5bff6d7eaeeae4bc20d75f54.tar.gz
rneovim-1befc494144fbf1d5bff6d7eaeeae4bc20d75f54.tar.bz2
rneovim-1befc494144fbf1d5bff6d7eaeeae4bc20d75f54.zip
Use xmalloc() and xmemdupz() in file_pat_to_reg_pat()
Unfortunately there's still a case where NULL can be returned from file_pat_to_reg_pat(). xmemdupz() and xmallocz() aren't static anymore. There are many use cases for these function.
Diffstat (limited to 'src/fileio.c')
-rw-r--r--src/fileio.c14
1 files changed, 5 insertions, 9 deletions
diff --git a/src/fileio.c b/src/fileio.c
index 178f4e694c..bef1ead599 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -8048,7 +8048,7 @@ int match_file_list(char_u *list, char_u *sfname, char_u *ffname)
* If FEAT_OSFILETYPE defined then pass initial <type> through unchanged. Eg:
* '<html>myfile' becomes '<html>^myfile$' -- leonard.
*
- * Returns NULL when out of memory.
+ * Returns NULL on failure.
*/
char_u *
file_pat_to_reg_pat (
@@ -8058,7 +8058,7 @@ file_pat_to_reg_pat (
int no_bslash /* Don't use a backward slash as pathsep */
)
{
- int size;
+ size_t size;
char_u *endp;
char_u *reg_pat;
char_u *p;
@@ -8085,9 +8085,7 @@ file_pat_to_reg_pat (
check_length = p - pat + 1;
if (p + 1 >= pat_end) {
/* The 'pattern' is a filetype check ONLY */
- reg_pat = (char_u *)alloc(check_length + 1);
- memmove(reg_pat, pat, (size_t)check_length);
- reg_pat[check_length] = NUL;
+ reg_pat = xmemdupz(pat, (size_t)check_length);
return reg_pat;
}
}
@@ -8095,7 +8093,7 @@ file_pat_to_reg_pat (
}
pat += check_length;
- size = 2 + check_length;
+ size = 2 + (size_t)check_length;
#else
size = 2; /* '^' at start, '$' at end */
#endif
@@ -8125,9 +8123,7 @@ file_pat_to_reg_pat (
break;
}
}
- reg_pat = alloc(size + 1);
- if (reg_pat == NULL)
- return NULL;
+ reg_pat = xmalloc(size + 1);
#ifdef FEAT_OSFILETYPE
/* Copy the type check in to the start. */