[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 3/3] maint: avoid warnings from sparse tool
From: |
Bernhard Voelker |
Subject: |
[PATCH 3/3] maint: avoid warnings from sparse tool |
Date: |
Thu, 6 Jan 2022 16:47:40 +0100 |
https://sparse.docs.kernel.org/
Running the tool against unviled the following warnings:
find/parser.c:328:7: warning: Using plain integer as NULL pointer
find/parser.c:328:10: warning: Using plain integer as NULL pointer
find/parser.c:328:13: warning: Using plain integer as NULL pointer
find/parser.c:466:49: warning: Using plain integer as NULL pointer
find/parser.c:656:45: warning: Using plain integer as NULL pointer
find/print.c:1024:30: warning: Using plain integer as NULL pointer
lib/regexprops.c:531:7: warning: symbol 'options' shadows an earlier one
lib/regextype.c:48:24: warning: symbol 'regex_map' was not declared. Should
it be static?
locate/locate.c:131:25: warning: symbol 'check_existence' was not declared.
Should it be static?
locate/locate.c:207:12: warning: symbol 'metacharacters' was not declared.
Should it be static?
xargs/xargs.c:902:24: warning: symbol 'state' shadows an earlier one
xargs/xargs.c:542:23: warning: Using plain integer as NULL pointer
The fixes for these findings are all trivial, so let's apply them.
* find/parser.c (parse_table): Initialize pointer-type members of
the last element with NULL instead of 0.
(get_noop): Compare to NULL as end condition of for-loop.
(find_parser): Likewise.
* find/print.c (do_fprintf): Initialize linkname with NULL instead of 0.
* lib/regexprops.c (describe_all): Rename local variable options
to regopts to avoid name shadowing.
* lib/regextype.c (regex_map): Declare static.
* locate/locate.c (check_existence): Likewise.
(metacharacters): Likewise.
* xargs/xargs.c (main): Set eof_str to NULL instead of 0.
---
find/parser.c | 6 +++---
find/print.c | 2 +-
lib/regexprops.c | 6 +++---
lib/regextype.c | 2 +-
locate/locate.c | 4 ++--
xargs/xargs.c | 2 +-
6 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/find/parser.c b/find/parser.c
index 152f0fcd..c728fd6b 100644
--- a/find/parser.c
+++ b/find/parser.c
@@ -325,7 +325,7 @@ static struct parser_table const parse_table[] =
{ARG_TEST, "-help", parse_help, NULL}, /* GNU */
{ARG_TEST, "version", parse_version, NULL}, /* GNU */
{ARG_TEST, "-version", parse_version, NULL}, /* GNU */
- {0, 0, 0, 0}
+ {0, NULL, NULL, NULL}
};
@@ -463,7 +463,7 @@ get_noop (void)
int i;
if (NULL == noop)
{
- for (i = 0; parse_table[i].parser_name != 0; i++)
+ for (i = 0; parse_table[i].parser_name != NULL; i++)
{
if (ARG_NOOP ==parse_table[i].type)
{
@@ -653,7 +653,7 @@ find_parser (const char *search_name)
if (*search_name == '-')
search_name++;
- for (i = 0; parse_table[i].parser_name != 0; i++)
+ for (i = 0; parse_table[i].parser_name != NULL; i++)
{
if (strcmp (parse_table[i].parser_name, search_name) == 0)
{
diff --git a/find/print.c b/find/print.c
index 62f7d22b..e7f0ba37 100644
--- a/find/print.c
+++ b/find/print.c
@@ -1021,7 +1021,7 @@ do_fprintf (struct format_val *dest,
/* sanitised */
#ifdef S_ISLNK
{
- char *linkname = 0;
+ char *linkname = NULL;
if (S_ISLNK (stat_buf->st_mode))
{
diff --git a/lib/regexprops.c b/lib/regexprops.c
index 7cc49b78..f7adbd3a 100644
--- a/lib/regexprops.c
+++ b/lib/regexprops.c
@@ -528,7 +528,7 @@ describe_all (const char *contextname,
const char *up)
{
const char *name, *next, *previous;
- int options;
+ int regopts;
int i, parent;
copying ();
@@ -542,7 +542,7 @@ describe_all (const char *contextname,
previous = "";
for (i=0;
- options = get_regex_type_flags (i),
+ regopts = get_regex_type_flags (i),
name=get_regex_type_name (i);
++i)
{
@@ -568,7 +568,7 @@ describe_all (const char *contextname,
}
else
{
- describe_regex_syntax (options);
+ describe_regex_syntax (regopts);
}
previous = name;
}
diff --git a/lib/regextype.c b/lib/regextype.c
index c87c5e70..9765b9b2 100644
--- a/lib/regextype.c
+++ b/lib/regextype.c
@@ -45,7 +45,7 @@ struct tagRegexTypeMap
int option_val;
};
-struct tagRegexTypeMap regex_map[] =
+static struct tagRegexTypeMap regex_map[] =
{
{ "findutils-default", CONTEXT_FINDUTILS,
RE_SYNTAX_EMACS|RE_DOT_NEWLINE },
{ "ed", CONTEXT_GENERIC, RE_SYNTAX_ED
},
diff --git a/locate/locate.c b/locate/locate.c
index 84705e90..da161ff7 100644
--- a/locate/locate.c
+++ b/locate/locate.c
@@ -128,7 +128,7 @@ enum ExistenceCheckType
};
/* Check for existence of files before printing them out? */
-enum ExistenceCheckType check_existence = ACCEPT_EITHER;
+static enum ExistenceCheckType check_existence = ACCEPT_EITHER;
static int follow_symlinks = 1;
@@ -204,7 +204,7 @@ get_short (FILE *fp)
return x;
}
-const char * const metacharacters = "*?[]\\";
+static const char * const metacharacters = "*?[]\\";
/* Return nonzero if S contains any shell glob characters.
*/
diff --git a/xargs/xargs.c b/xargs/xargs.c
index eedee2d2..2951b005 100644
--- a/xargs/xargs.c
+++ b/xargs/xargs.c
@@ -539,7 +539,7 @@ main (int argc, char **argv)
if (optarg && (strlen (optarg) > 0))
eof_str = optarg;
else
- eof_str = 0;
+ eof_str = NULL;
break;
case 'h':
--
2.34.1