From 2337869fbf8b967eb53ee57f978f3751987e43dc Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 12 Jul 2021 00:00:20 -0700 Subject: [PATCH 2/5] Pacify gcc 11.1.1 -Wanalyzer-null-argument MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * lib-src/etags.c (regexp): Omit member force_explicit_name, since it’s always true. All uses removed. This lets us remove calls to strlen (name) where GCC isn’t smart enough to deduce that name must be nonnull. * lib-src/movemail.c (main): Fix bug that could cause link (tempname, NULL) to be called. * src/emacs.c (argmatch): Break check into two ‘if’s, since GCC doesn’t seem to be smart enough to check the single ‘if’. * src/gtkutil.c (xg_update_menu_item): Fix bug where strcmp could be given a NULL arg. * src/xfont.c (xfont_list_family): Use nonnull value for dummy initial value. --- lib-src/etags.c | 49 ++++++++++++++++++---------------------------- lib-src/movemail.c | 14 +++++-------- src/emacs.c | 4 +++- src/gtkutil.c | 2 +- src/xfont.c | 5 ++++- 5 files changed, 32 insertions(+), 42 deletions(-) diff --git a/lib-src/etags.c b/lib-src/etags.c index c39c93db33..88b49f803e 100644 --- a/lib-src/etags.c +++ b/lib-src/etags.c @@ -340,7 +340,6 @@ #define xrnew(op, n, m) ((op) = xnrealloc (op, n, (m) * sizeof *(op))) struct re_pattern_buffer *pat; /* the compiled pattern */ struct re_registers regs; /* re registers */ bool error_signaled; /* already signaled for this regexp */ - bool force_explicit_name; /* do not allow implicit tag name */ bool ignore_case; /* ignore case when matching */ bool multi_line; /* do a multi-line match on the whole file */ } regexp; @@ -6910,7 +6909,6 @@ add_regex (char *regexp_pattern, language *lang) struct re_pattern_buffer *patbuf; regexp *rp; bool - force_explicit_name = true, /* do not use implicit tag names */ ignore_case = false, /* case is significant */ multi_line = false, /* matches are done one line at a time */ single_line = false; /* dot does not match newline */ @@ -6949,7 +6947,8 @@ add_regex (char *regexp_pattern, language *lang) case 'N': if (modifiers == name) error ("forcing explicit tag name but no name, ignoring"); - force_explicit_name = true; + /* This option has no effect and is present only for backward + compatibility. */ break; case 'i': ignore_case = true; @@ -7004,7 +7003,6 @@ add_regex (char *regexp_pattern, language *lang) p_head->pat = patbuf; p_head->name = savestr (name); p_head->error_signaled = false; - p_head->force_explicit_name = force_explicit_name; p_head->ignore_case = ignore_case; p_head->multi_line = multi_line; } @@ -7144,20 +7142,15 @@ regex_tag_multiline (void) name = NULL; else /* make a named tag */ name = substitute (buffer, rp->name, &rp->regs); - if (rp->force_explicit_name) - { - /* Force explicit tag name, if a name is there. */ - pfnote (name, true, buffer + linecharno, - charno - linecharno + 1, lineno, linecharno); - - if (debug) - fprintf (stderr, "%s on %s:%"PRIdMAX": %s\n", - name ? name : "(unnamed)", curfdp->taggedfname, - lineno, buffer + linecharno); - } - else - make_tag (name, strlen (name), true, buffer + linecharno, - charno - linecharno + 1, lineno, linecharno); + + /* Force explicit tag name, if a name is there. */ + pfnote (name, true, buffer + linecharno, + charno - linecharno + 1, lineno, linecharno); + + if (debug) + fprintf (stderr, "%s on %s:%"PRIdMAX": %s\n", + name ? name : "(unnamed)", curfdp->taggedfname, + lineno, buffer + linecharno); break; } } @@ -7471,18 +7464,14 @@ readline (linebuffer *lbp, FILE *stream) name = NULL; else /* make a named tag */ name = substitute (lbp->buffer, rp->name, &rp->regs); - if (rp->force_explicit_name) - { - /* Force explicit tag name, if a name is there. */ - pfnote (name, true, lbp->buffer, match, lineno, linecharno); - if (debug) - fprintf (stderr, "%s on %s:%"PRIdMAX": %s\n", - name ? name : "(unnamed)", curfdp->taggedfname, - lineno, lbp->buffer); - } - else - make_tag (name, strlen (name), true, - lbp->buffer, match, lineno, linecharno); + + /* Force explicit tag name, if a name is there. */ + pfnote (name, true, lbp->buffer, match, lineno, linecharno); + + if (debug) + fprintf (stderr, "%s on %s:%"PRIdMAX": %s\n", + name ? name : "(unnamed)", curfdp->taggedfname, + lineno, lbp->buffer); break; } } diff --git a/lib-src/movemail.c b/lib-src/movemail.c index cfdebccb8d..e683da179d 100644 --- a/lib-src/movemail.c +++ b/lib-src/movemail.c @@ -270,6 +270,7 @@ main (int argc, char **argv) You might also wish to verify that your system is one which uses lock files for this purpose. Some systems use other methods. */ + bool lockname_unlinked = false; inname_len = strlen (inname); lockname = xmalloc (inname_len + sizeof ".lock"); strcpy (lockname, inname); @@ -312,15 +313,10 @@ main (int argc, char **argv) Five minutes should be good enough to cope with crashes and wedgitude, and long enough to avoid being fooled by time differences between machines. */ - if (stat (lockname, &st) >= 0) - { - time_t now = time (0); - if (st.st_ctime < now - 300) - { - unlink (lockname); - lockname = 0; - } - } + if (!lockname_unlinked + && stat (lockname, &st) == 0 + && st.st_ctime < time (0) - 300) + lockname_unlinked = unlink (lockname) == 0 || errno == ENOENT; } delete_lockname = lockname; diff --git a/src/emacs.c b/src/emacs.c index b7982ece64..866e43fda9 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -670,7 +670,9 @@ argmatch (char **argv, int argc, const char *sstr, const char *lstr, } arglen = (valptr != NULL && (p = strchr (arg, '=')) != NULL ? p - arg : strlen (arg)); - if (lstr == 0 || arglen < minlen || strncmp (arg, lstr, arglen) != 0) + if (!lstr) + return 0; + if (arglen < minlen || strncmp (arg, lstr, arglen) != 0) return 0; else if (valptr == NULL) { diff --git a/src/gtkutil.c b/src/gtkutil.c index dee2a93089..313cfc82c2 100644 --- a/src/gtkutil.c +++ b/src/gtkutil.c @@ -3221,7 +3221,7 @@ xg_update_menu_item (widget_value *val, gtk_label_set_text (wkey, utf8_key); } - if (! old_label || strcmp (utf8_label, old_label) != 0) + if (utf8_label && (! old_label || strcmp (utf8_label, old_label) != 0)) { label_changed = true; gtk_label_set_text (wlbl, utf8_label); diff --git a/src/xfont.c b/src/xfont.c index 0570ee96a9..81d356175a 100644 --- a/src/xfont.c +++ b/src/xfont.c @@ -596,7 +596,10 @@ xfont_list_family (struct frame *f) char **names; int num_fonts, i; Lisp_Object list; - char *last_family UNINIT; + char const *last_family; +#if defined GCC_LINT || defined lint + last_family = ""; +#endif int last_len; block_input (); -- 2.30.2