vim-patch:8.0.1512: warning for possibly using NULL pointer

Problem:    Warning for possibly using NULL pointer. (Coverity)
Solution:   Skip using the pointer if it's NULL.
e4db7aedab
This commit is contained in:
Jan Edmund Lazo
2018-07-23 00:23:18 -04:00
parent 9fbbec76aa
commit 84b8612987
7 changed files with 45 additions and 32 deletions

View File

@@ -4420,7 +4420,7 @@ do_arg_all (
if (i < alist->al_ga.ga_len if (i < alist->al_ga.ga_len
&& (AARGLIST(alist)[i].ae_fnum == buf->b_fnum && (AARGLIST(alist)[i].ae_fnum == buf->b_fnum
|| path_full_compare(alist_name(&AARGLIST(alist)[i]), || path_full_compare(alist_name(&AARGLIST(alist)[i]),
buf->b_ffname, TRUE) & kEqualFiles)) { buf->b_ffname, true) & kEqualFiles)) {
int weight = 1; int weight = 1;
if (old_curtab == curtab) { if (old_curtab == curtab) {

View File

@@ -4977,7 +4977,8 @@ void fix_help_buffer(void)
while (*p != NUL) { while (*p != NUL) {
copy_option_part(&p, NameBuff, MAXPATHL, ","); copy_option_part(&p, NameBuff, MAXPATHL, ",");
rt = (char_u *)vim_getenv("VIMRUNTIME"); rt = (char_u *)vim_getenv("VIMRUNTIME");
if (path_full_compare(rt, NameBuff, FALSE) != kEqualFiles) { if (rt != NULL
&& path_full_compare(rt, NameBuff, false) != kEqualFiles) {
int fcount; int fcount;
char_u **fnames; char_u **fnames;
FILE *fd; FILE *fd;
@@ -5197,8 +5198,9 @@ static void helptags_one(char_u *dir, char_u *ext, char_u *tagfname,
* add the "help-tags" tag. * add the "help-tags" tag.
*/ */
ga_init(&ga, (int)sizeof(char_u *), 100); ga_init(&ga, (int)sizeof(char_u *), 100);
if (add_help_tags || path_full_compare((char_u *)"$VIMRUNTIME/doc", if (add_help_tags
dir, FALSE) == kEqualFiles) { || path_full_compare((char_u *)"$VIMRUNTIME/doc",
dir, false) == kEqualFiles) {
s = xmalloc(18 + STRLEN(tagfname)); s = xmalloc(18 + STRLEN(tagfname));
sprintf((char *)s, "help-tags\t%s\t1\n", tagfname); sprintf((char *)s, "help-tags\t%s\t1\n", tagfname);
GA_APPEND(char_u *, &ga, s); GA_APPEND(char_u *, &ga, s);

View File

@@ -1365,11 +1365,11 @@ recover_names (
*/ */
if (curbuf->b_ml.ml_mfp != NULL if (curbuf->b_ml.ml_mfp != NULL
&& (p = curbuf->b_ml.ml_mfp->mf_fname) != NULL) { && (p = curbuf->b_ml.ml_mfp->mf_fname) != NULL) {
for (int i = 0; i < num_files; ++i) for (int i = 0; i < num_files; i++) {
if (path_full_compare(p, files[i], TRUE) & kEqualFiles) { if (path_full_compare(p, files[i], true) & kEqualFiles) {
/* Remove the name from files[i]. Move further entries // Remove the name from files[i]. Move further entries
* down. When the array becomes empty free it here, since // down. When the array becomes empty free it here, since
* FreeWild() won't be called below. */ // FreeWild() won't be called below.
xfree(files[i]); xfree(files[i]);
if (--num_files == 0) if (--num_files == 0)
xfree(files); xfree(files);
@@ -1377,6 +1377,7 @@ recover_names (
for (; i < num_files; ++i) for (; i < num_files; ++i)
files[i] = files[i + 1]; files[i] = files[i + 1];
} }
}
} }
if (nr > 0) { if (nr > 0) {
file_count += num_files; file_count += num_files;

View File

@@ -52,7 +52,8 @@
/// @param s2 Second file name. /// @param s2 Second file name.
/// @param checkname When both files don't exist, only compare their names. /// @param checkname When both files don't exist, only compare their names.
/// @return Enum of type FileComparison. @see FileComparison. /// @return Enum of type FileComparison. @see FileComparison.
FileComparison path_full_compare(char_u *s1, char_u *s2, int checkname) FileComparison path_full_compare(char_u *const s1, char_u *const s2,
const bool checkname)
{ {
assert(s1 && s2); assert(s1 && s2);
char_u exp1[MAXPATHL]; char_u exp1[MAXPATHL];

View File

@@ -2043,9 +2043,11 @@ char_u *did_set_spelllang(win_T *wp)
dont_use_region = true; dont_use_region = true;
// Check if we loaded this language before. // Check if we loaded this language before.
for (slang = first_lang; slang != NULL; slang = slang->sl_next) for (slang = first_lang; slang != NULL; slang = slang->sl_next) {
if (path_full_compare(lang, slang->sl_fname, FALSE) == kEqualFiles) if (path_full_compare(lang, slang->sl_fname, false) == kEqualFiles) {
break; break;
}
}
} else { } else {
filename = false; filename = false;
if (len > 3 && lang[len - 3] == '_') { if (len > 3 && lang[len - 3] == '_') {
@@ -2085,8 +2087,9 @@ char_u *did_set_spelllang(win_T *wp)
} }
// Loop over the languages, there can be several files for "lang". // Loop over the languages, there can be several files for "lang".
for (slang = first_lang; slang != NULL; slang = slang->sl_next) for (slang = first_lang; slang != NULL; slang = slang->sl_next) {
if (filename ? path_full_compare(lang, slang->sl_fname, FALSE) == kEqualFiles if (filename
? path_full_compare(lang, slang->sl_fname, false) == kEqualFiles
: STRICMP(lang, slang->sl_name) == 0) { : STRICMP(lang, slang->sl_name) == 0) {
region_mask = REGION_ALL; region_mask = REGION_ALL;
if (!filename && region != NULL) { if (!filename && region != NULL) {
@@ -2116,6 +2119,7 @@ char_u *did_set_spelllang(win_T *wp)
nobreak = true; nobreak = true;
} }
} }
}
} }
// round 0: load int_wordlist, if possible. // round 0: load int_wordlist, if possible.
@@ -2137,17 +2141,21 @@ char_u *did_set_spelllang(win_T *wp)
// If it was already found above then skip it. // If it was already found above then skip it.
for (c = 0; c < ga.ga_len; ++c) { for (c = 0; c < ga.ga_len; ++c) {
p = LANGP_ENTRY(ga, c)->lp_slang->sl_fname; p = LANGP_ENTRY(ga, c)->lp_slang->sl_fname;
if (p != NULL && path_full_compare(spf_name, p, FALSE) == kEqualFiles) if (p != NULL
&& path_full_compare(spf_name, p, false) == kEqualFiles) {
break; break;
}
} }
if (c < ga.ga_len) if (c < ga.ga_len)
continue; continue;
} }
// Check if it was loaded already. // Check if it was loaded already.
for (slang = first_lang; slang != NULL; slang = slang->sl_next) for (slang = first_lang; slang != NULL; slang = slang->sl_next) {
if (path_full_compare(spf_name, slang->sl_fname, FALSE) == kEqualFiles) if (path_full_compare(spf_name, slang->sl_fname, false) == kEqualFiles) {
break; break;
}
}
if (slang == NULL) { if (slang == NULL) {
// Not loaded, try loading it now. The language name includes the // Not loaded, try loading it now. The language name includes the
// region name, the region is ignored otherwise. for int_wordlist // region name, the region is ignored otherwise. for int_wordlist

View File

@@ -1786,7 +1786,7 @@ spell_reload_one (
bool didit = false; bool didit = false;
for (slang = first_lang; slang != NULL; slang = slang->sl_next) { for (slang = first_lang; slang != NULL; slang = slang->sl_next) {
if (path_full_compare(fname, slang->sl_fname, FALSE) == kEqualFiles) { if (path_full_compare(fname, slang->sl_fname, false) == kEqualFiles) {
slang_clear(slang); slang_clear(slang);
if (spell_load_file(fname, NULL, slang, false) == NULL) if (spell_load_file(fname, NULL, slang, false) == NULL)
// reloading failed, clear the language // reloading failed, clear the language
@@ -4714,9 +4714,11 @@ static void spell_make_sugfile(spellinfo_T *spin, char_u *wfname)
// pointer-linked version of the trie. And it avoids having two versions // pointer-linked version of the trie. And it avoids having two versions
// of the code for the soundfolding stuff. // of the code for the soundfolding stuff.
// It might have been done already by spell_reload_one(). // It might have been done already by spell_reload_one().
for (slang = first_lang; slang != NULL; slang = slang->sl_next) for (slang = first_lang; slang != NULL; slang = slang->sl_next) {
if (path_full_compare(wfname, slang->sl_fname, FALSE) == kEqualFiles) if (path_full_compare(wfname, slang->sl_fname, false) == kEqualFiles) {
break; break;
}
}
if (slang == NULL) { if (slang == NULL) {
spell_message(spin, (char_u *)_("Reading back spell file...")); spell_message(spin, (char_u *)_("Reading back spell file..."));
slang = spell_load_file(wfname, NULL, NULL, false); slang = spell_load_file(wfname, NULL, NULL, false);

View File

@@ -2289,7 +2289,7 @@ static char_u *tag_full_fname(tagptrs_T *tagp)
{ {
int c = *tagp->fname_end; int c = *tagp->fname_end;
*tagp->fname_end = NUL; *tagp->fname_end = NUL;
char_u *fullname = expand_tag_fname(tagp->fname, tagp->tag_fname, FALSE); char_u *fullname = expand_tag_fname(tagp->fname, tagp->tag_fname, false);
*tagp->fname_end = c; *tagp->fname_end = c;
return fullname; return fullname;
@@ -2363,8 +2363,8 @@ jumpto_tag (
* Expand file name, when needed (for environment variables). * Expand file name, when needed (for environment variables).
* If 'tagrelative' option set, may change file name. * If 'tagrelative' option set, may change file name.
*/ */
fname = expand_tag_fname(fname, tagp.tag_fname, TRUE); fname = expand_tag_fname(fname, tagp.tag_fname, true);
tofree_fname = fname; /* free() it later */ tofree_fname = fname; // free() it later
/* /*
* Check if the file with the tag exists before abandoning the current * Check if the file with the tag exists before abandoning the current
@@ -2615,13 +2615,12 @@ erret:
return retval; return retval;
} }
/* // If "expand" is true, expand wildcards in fname.
* If "expand" is TRUE, expand wildcards in fname. // If 'tagrelative' option set, change fname (name of file containing tag)
* If 'tagrelative' option set, change fname (name of file containing tag) // according to tag_fname (name of tag file containing fname).
* according to tag_fname (name of tag file containing fname). // Returns a pointer to allocated memory.
* Returns a pointer to allocated memory. static char_u *expand_tag_fname(char_u *fname, char_u *const tag_fname,
*/ const bool expand)
static char_u *expand_tag_fname(char_u *fname, char_u *tag_fname, int expand)
{ {
char_u *p; char_u *p;
char_u *expanded_fname = NULL; char_u *expanded_fname = NULL;
@@ -2676,8 +2675,8 @@ static int test_for_current(char_u *fname, char_u *fname_end, char_u *tag_fname,
c = *fname_end; c = *fname_end;
*fname_end = NUL; *fname_end = NUL;
} }
fullname = expand_tag_fname(fname, tag_fname, TRUE); fullname = expand_tag_fname(fname, tag_fname, true);
retval = (path_full_compare(fullname, buf_ffname, TRUE) & kEqualFiles); retval = (path_full_compare(fullname, buf_ffname, true) & kEqualFiles);
xfree(fullname); xfree(fullname);
*fname_end = c; *fname_end = c;
} }