threads / patch / 31609

patchgrep.c: Fix some sparse warnings

Subject: [PATCH] grep.c: Fix some sparse warnings

## tl;dr

One message between Sep 19, 2012 and Sep 19, 2012. Diffs are folded; open one to read it.

replies: 0people: 1as markdown or json

Ramsay Jones· Sep 19, 2012, 18:04 UTC · lore
In particular, sparse complains as follows:
        SP grep.c
    grep.c:1472:5: warning: symbol 'grep_source_load' was not \
        declared. Should it be static?
    grep.c:1500:5: warning: symbol 'grep_source_is_binary' was not \
        declared. Should it be static?

These warnings actually illustrate a known bug in sparse. The forward declarations of these functions (on lines 6-7) include the static modifier. These forward declarations convey the file scope property to the later function definitions. Note that the function definition does not have to include the static modifier for this to take effect.

In order to suppress the warnings, we simply include the (redundant) static modifier in the function definitions. Note that repeating the modifier, while not needed by the definition of C, does make it clear to the human reader, at the point of definition, that the symbol has file scope.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
---
 grep.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Show changes to grep.c +2 −2
diff --git a/grep.c b/grep.c
index c7f8a47..898be6e 100644
--- a/grep.c
+++ b/grep.c
@@ -1469,7 +1469,7 @@ static int grep_source_load_file(struct grep_source *gs)
 	return 0;
 }
 
-int grep_source_load(struct grep_source *gs)
+static int grep_source_load(struct grep_source *gs)
 {
 	if (gs->buf)
 		return 0;
@@ -1497,7 +1497,7 @@ void grep_source_load_driver(struct grep_source *gs)
 	grep_attr_unlock();
 }
 
-int grep_source_is_binary(struct grep_source *gs)
+static int grep_source_is_binary(struct grep_source *gs)
 {
 	grep_source_load_driver(gs);
 	if (gs->driver->binary != -1)
-- 
1.7.12

← back to recent threads