Skip to contentSkip to conversation

tests: nft-parsing-test: fix warning - ignoring return value of fgets

PATCH In review Harsha Sharma 2 participants 2 messages Dec 29, 2017 – Dec 30, 2017 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests: nft-parsing-test: fix warning - ignoring return value of fgets

This patch fixes compilation warning: ignoring return value of fgets.

---
 tests/nft-parsing-test.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tests/nft-parsing-test.c +2 -1
index d25a73e..97f402d 100644
@@ -80,7 +80,8 @@ static int compare_test(uint32_t type, struct nftnl_ruleset *rs,
 	}
 
 	rewind(fp);
-	fgets(orig, sizeof(orig), fp);
+	if (fgets(orig, sizeof(orig), fp) == NULL)
+		fprintf(stderr, "Error in reading or end of file.\n");
 
 	if (strncmp(orig, out, strlen(out)) == 0) {
 		if (update)
Signature · 1 line
2.11.0
#1 lore raw

Hi Harsha,

Quoted 12 lines · Harsha Sharma

This patch fixes compilation warning: ignoring return value of fgets.

---
 tests/nft-parsing-test.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tests/nft-parsing-test.c +0 -0
index d25a73e..97f402d 100644

tests/nft-parsing-test.c static int compare_test(uint32_t type, struct nftnl_ruleset *rs, · line 84

Quoted 6 lines
tests/nft-parsing-test.c +2 -1
@@ -80,7 +80,8 @@ static int compare_test(uint32_t type, struct nftnl_ruleset *rs,
 	}
 
 	rewind(fp);
-	fgets(orig, sizeof(orig), fp);
+	if (fgets(orig, sizeof(orig), fp) == NULL)
+		fprintf(stderr, "Error in reading or end of file.\n");

Did you test this? Are you sure this is the right fix for this? IIRC, EOF is reported via NULL too for fgets.

Thanks.