* [PATCH] scripts: confdata: Fix fwrite warning
@ 2010-06-02 14:44 Thomas Weber
2010-06-04 22:16 ` Andrew Morton
0 siblings, 1 reply; 2+ messages in thread
From: Thomas Weber @ 2010-06-02 14:44 UTC (permalink / raw)
To: zippel; +Cc: Thomas Weber, linux-kbuild, linux-kernel
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.
Signed-off-by: Thomas Weber <weber@corscience.de>
---
scripts/kconfig/confdata.c | 15 ++++++++++++---
1 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index c4dec80..4741fea 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -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)
--
1.7.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] scripts: confdata: Fix fwrite warning
2010-06-02 14:44 [PATCH] scripts: confdata: Fix fwrite warning Thomas Weber
@ 2010-06-04 22:16 ` Andrew Morton
0 siblings, 0 replies; 2+ messages in thread
From: Andrew Morton @ 2010-06-04 22:16 UTC (permalink / raw)
To: Thomas Weber; +Cc: zippel, linux-kbuild, linux-kernel
On Wed, 2 Jun 2010 16:44:19 +0200
Thomas Weber <weber@corscience.de> 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.
>
> Signed-off-by: Thomas Weber <weber@corscience.de>
> ---
> scripts/kconfig/confdata.c | 15 ++++++++++++---
> 1 files changed, 12 insertions(+), 3 deletions(-)
>
> diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
> index c4dec80..4741fea 100644
> --- a/scripts/kconfig/confdata.c
> +++ b/scripts/kconfig/confdata.c
> @@ -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) ;)
> 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;
> + }
Dittoes.
Also, this patch would be neater if it added a little helper function
around fwrite(), rather than triplicating the same code sequence.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-06-04 22:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-02 14:44 [PATCH] scripts: confdata: Fix fwrite warning Thomas Weber
2010-06-04 22:16 ` Andrew Morton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).