Skip to contentSkip to conversation

scripts: confdata: Fix fwrite warning

PATCH In review Thomas Weber 2 participants 2 messages Jun 2, 2010 – Jun 4, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scripts: confdata: Fix fwrite warning

I get for:
scripts/kconfig/confdata.c:508
scripts/kconfig/confdata.c:759
scripts/kconfig/confdata.c:760

warning: ignoring return value of ‘fwrite’, declared with attribute warn_unused_result

So check the return value and handle the error.

---
 scripts/kconfig/confdata.c |   15 ++++++++++++---
 1 files changed, 12 insertions(+), 3 deletions(-)
scripts/kconfig/confdata.c +12 -3
index c4dec80..4741fea 100644
@@ -505,7 +505,10 @@ int conf_write(const char *name)
 				while (1) {
 					l = strcspn(str, "\"\\");
 					if (l) {
-						fwrite(str, l, 1, out);
+						if (fwrite(str, l, 1, out) != 1) {
+							fprintf(stderr, "write str failed\n");
+							return 1;
+						}
 						str += l;
 					}
 					if (!*str)
@@ -756,8 +759,14 @@ int conf_write_autoconf(void)
 			while (1) {
 				l = strcspn(str, "\"\\");
 				if (l) {
-					fwrite(str, l, 1, out);
-					fwrite(str, l, 1, out_h);
+					if (fwrite(str, l, 1, out) != 1) {
+						fprintf(stderr, "write str failed\n");
+						return 1;
+					}
+					if (fwrite(str, l, 1, out_h) != 1) {
+						fprintf(stderr, "write str failed\n");
+						return 1;
+					}
 					str += l;
 				}
 				if (!*str)
Signature · 1 line
1.7.1
#1 lore raw
Quoted 19 lines · On Wed, 2 Jun 2010 16:44:19 +0200 Thomas Weber <[email protected]> wrote:

I get for:
scripts/kconfig/confdata.c:508
scripts/kconfig/confdata.c:759
scripts/kconfig/confdata.c:760

warning: ignoring return value of ___fwrite___, declared with attribute warn_unused_result

So check the return value and handle the error.

---
 scripts/kconfig/confdata.c |   15 ++++++++++++---
 1 files changed, 12 insertions(+), 3 deletions(-)
scripts/kconfig/confdata.c +0 -0
index c4dec80..4741fea 100644

scripts/kconfig/confdata.c int conf_write(const char *name) · line 511

Quoted 8 lines
scripts/kconfig/confdata.c +4 -1
@@ -505,7 +505,10 @@ int conf_write(const char *name)
 				while (1) {
 					l = strcspn(str, "\"\\");
 					if (l) {
-						fwrite(str, l, 1, out);
+						if (fwrite(str, l, 1, out) != 1) {
+							fprintf(stderr, "write str failed\n");
+							return 1;
+						}

Missing an fclose(out), although that probably doesn't matter a lot in practice

Also, we prefer to avoid putting `return' statements deep inside large C functions as they can easily lead to resource leaks. Such as forgetting to fclose(out) ;)

Quoted 7 lines
scripts/kconfig/confdata.c +0 -0
 						str += l;
 					}
 					if (!*str)
@@ -756,8 +759,14 @@ int conf_write_autoconf(void)
 			while (1) {
 				l = strcspn(str, "\"\\");
 				if (l) {

scripts/kconfig/confdata.c int conf_write_autoconf(void) · line 769

Quoted 10 lines
scripts/kconfig/confdata.c +8 -2
-					fwrite(str, l, 1, out);
-					fwrite(str, l, 1, out_h);
+					if (fwrite(str, l, 1, out) != 1) {
+						fprintf(stderr, "write str failed\n");
+						return 1;
+					}
+					if (fwrite(str, l, 1, out_h) != 1) {
+						fprintf(stderr, "write str failed\n");
+						return 1;
+					}

Dittoes.

Also, this patch would be neater if it added a little helper function around fwrite(), rather than triplicating the same code sequence.