* [PATCH] kconfig: fix warnings in fgets/fwrite usage
@ 2010-08-12 5:56 Mike Frysinger
2010-08-17 5:46 ` Américo Wang
0 siblings, 1 reply; 4+ messages in thread
From: Mike Frysinger @ 2010-08-12 5:56 UTC (permalink / raw)
To: linux-kbuild, Roman Zippel; +Cc: linux-kernel
Add some helper functions that abort on failure, and change the fwrite
and fget calls to use those. This should kill off all the ugly gcc
warnings that some distros emit about ignoring return values due to
usage of warn_unused_result attributes.
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
scripts/kconfig/conf.c | 4 ++--
scripts/kconfig/confdata.c | 2 +-
scripts/kconfig/expr.c | 2 +-
scripts/kconfig/lkc.h | 24 ++++++++++++++++++++++++
4 files changed, 28 insertions(+), 4 deletions(-)
diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c
index 274f271..b382a39 100644
--- a/scripts/kconfig/conf.c
+++ b/scripts/kconfig/conf.c
@@ -108,7 +108,7 @@ static int conf_askvalue(struct symbol *sym, const char *def)
check_stdin();
case oldaskconfig:
fflush(stdout);
- fgets(line, 128, stdin);
+ xfgets(line, 128, stdin);
return 1;
default:
break;
@@ -306,7 +306,7 @@ static int conf_choice(struct menu *menu)
check_stdin();
case oldaskconfig:
fflush(stdout);
- fgets(line, 128, stdin);
+ xfgets(line, 128, stdin);
strip(line);
if (line[0] == '?') {
print_help(menu);
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index f81f263..7d9f271 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -412,7 +412,7 @@ static void conf_write_string(bool headerfile, const char *name,
while (1) {
l = strcspn(str, "\"\\");
if (l) {
- fwrite(str, l, 1, out);
+ xfwrite(str, l, 1, out);
str += l;
}
if (!*str)
diff --git a/scripts/kconfig/expr.c b/scripts/kconfig/expr.c
index 8f18e37..330e7c0 100644
--- a/scripts/kconfig/expr.c
+++ b/scripts/kconfig/expr.c
@@ -1087,7 +1087,7 @@ void expr_print(struct expr *e, void (*fn)(void *, struct symbol *, const char *
static void expr_print_file_helper(void *data, struct symbol *sym, const char *str)
{
- fwrite(str, strlen(str), 1, data);
+ xfwrite(str, strlen(str), 1, data);
}
void expr_fprint(struct expr *e, FILE *out)
diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h
index 76db065..a3bd66a 100644
--- a/scripts/kconfig/lkc.h
+++ b/scripts/kconfig/lkc.h
@@ -169,6 +169,30 @@ static inline bool sym_has_value(struct symbol *sym)
return sym->flags & SYMBOL_DEF_USER ? true : false;
}
+#define internal_error(fmt, args...) \
+do { \
+ fprintf(stderr, "%s:%s:%i: %s: " fmt "\n", __FILE__, \
+ __func__, __LINE__, _("internal error"), ## args); \
+ exit(1); \
+} while (0)
+
+#define xfwrite(ptr, size, nmemb, stream) \
+({ \
+ size_t _nmemb = (nmemb); \
+ size_t ret = fwrite(ptr, size, _nmemb, stream); \
+ if (ret != _nmemb) \
+ internal_error("%s", _("fwrite() came up short")); \
+ ret; \
+})
+
+#define xfgets(s, size, stream) \
+({ \
+ char *ret = fgets(s, size, stream); \
+ if (ret == NULL) \
+ internal_error("%s", _("fgets() came up short")); \
+ ret; \
+})
+
#ifdef __cplusplus
}
#endif
--
1.7.2
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] kconfig: fix warnings in fgets/fwrite usage
2010-08-12 5:56 [PATCH] kconfig: fix warnings in fgets/fwrite usage Mike Frysinger
@ 2010-08-17 5:46 ` Américo Wang
2010-08-17 6:44 ` Michal Marek
0 siblings, 1 reply; 4+ messages in thread
From: Américo Wang @ 2010-08-17 5:46 UTC (permalink / raw)
To: Mike Frysinger; +Cc: linux-kbuild, Roman Zippel, linux-kernel
On Thu, Aug 12, 2010 at 01:56:19AM -0400, Mike Frysinger wrote:
>Add some helper functions that abort on failure, and change the fwrite
>and fget calls to use those. This should kill off all the ugly gcc
>warnings that some distros emit about ignoring return values due to
>usage of warn_unused_result attributes.
>
>Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Looks good to me,
Acked-by: WANG Cong <xiyou.wangcong@gmail.com>
>---
> scripts/kconfig/conf.c | 4 ++--
> scripts/kconfig/confdata.c | 2 +-
> scripts/kconfig/expr.c | 2 +-
> scripts/kconfig/lkc.h | 24 ++++++++++++++++++++++++
> 4 files changed, 28 insertions(+), 4 deletions(-)
>
>diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c
>index 274f271..b382a39 100644
>--- a/scripts/kconfig/conf.c
>+++ b/scripts/kconfig/conf.c
>@@ -108,7 +108,7 @@ static int conf_askvalue(struct symbol *sym, const char *def)
> check_stdin();
> case oldaskconfig:
> fflush(stdout);
>- fgets(line, 128, stdin);
>+ xfgets(line, 128, stdin);
> return 1;
> default:
> break;
>@@ -306,7 +306,7 @@ static int conf_choice(struct menu *menu)
> check_stdin();
> case oldaskconfig:
> fflush(stdout);
>- fgets(line, 128, stdin);
>+ xfgets(line, 128, stdin);
> strip(line);
> if (line[0] == '?') {
> print_help(menu);
>diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
>index f81f263..7d9f271 100644
>--- a/scripts/kconfig/confdata.c
>+++ b/scripts/kconfig/confdata.c
>@@ -412,7 +412,7 @@ static void conf_write_string(bool headerfile, const char *name,
> while (1) {
> l = strcspn(str, "\"\\");
> if (l) {
>- fwrite(str, l, 1, out);
>+ xfwrite(str, l, 1, out);
> str += l;
> }
> if (!*str)
>diff --git a/scripts/kconfig/expr.c b/scripts/kconfig/expr.c
>index 8f18e37..330e7c0 100644
>--- a/scripts/kconfig/expr.c
>+++ b/scripts/kconfig/expr.c
>@@ -1087,7 +1087,7 @@ void expr_print(struct expr *e, void (*fn)(void *, struct symbol *, const char *
>
> static void expr_print_file_helper(void *data, struct symbol *sym, const char *str)
> {
>- fwrite(str, strlen(str), 1, data);
>+ xfwrite(str, strlen(str), 1, data);
> }
>
> void expr_fprint(struct expr *e, FILE *out)
>diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h
>index 76db065..a3bd66a 100644
>--- a/scripts/kconfig/lkc.h
>+++ b/scripts/kconfig/lkc.h
>@@ -169,6 +169,30 @@ static inline bool sym_has_value(struct symbol *sym)
> return sym->flags & SYMBOL_DEF_USER ? true : false;
> }
>
>+#define internal_error(fmt, args...) \
>+do { \
>+ fprintf(stderr, "%s:%s:%i: %s: " fmt "\n", __FILE__, \
>+ __func__, __LINE__, _("internal error"), ## args); \
>+ exit(1); \
>+} while (0)
>+
>+#define xfwrite(ptr, size, nmemb, stream) \
>+({ \
>+ size_t _nmemb = (nmemb); \
>+ size_t ret = fwrite(ptr, size, _nmemb, stream); \
>+ if (ret != _nmemb) \
>+ internal_error("%s", _("fwrite() came up short")); \
>+ ret; \
>+})
>+
>+#define xfgets(s, size, stream) \
>+({ \
>+ char *ret = fgets(s, size, stream); \
>+ if (ret == NULL) \
>+ internal_error("%s", _("fgets() came up short")); \
>+ ret; \
>+})
>+
> #ifdef __cplusplus
> }
> #endif
>--
>1.7.2
>
>--
>To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
>the body of a message to majordomo@vger.kernel.org
>More majordomo info at http://vger.kernel.org/majordomo-info.html
>Please read the FAQ at http://www.tux.org/lkml/
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] kconfig: fix warnings in fgets/fwrite usage
2010-08-17 5:46 ` Américo Wang
@ 2010-08-17 6:44 ` Michal Marek
2010-08-18 5:36 ` Mike Frysinger
0 siblings, 1 reply; 4+ messages in thread
From: Michal Marek @ 2010-08-17 6:44 UTC (permalink / raw)
To: Américo Wang
Cc: Mike Frysinger, linux-kbuild, Roman Zippel, linux-kernel
On 17.8.2010 07:46, Américo Wang wrote:
> On Thu, Aug 12, 2010 at 01:56:19AM -0400, Mike Frysinger wrote:
>> Add some helper functions that abort on failure, and change the fwrite
>> and fget calls to use those. This should kill off all the ugly gcc
>> warnings that some distros emit about ignoring return values due to
>> usage of warn_unused_result attributes.
>>
>> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
>
> Looks good to me,
>
> Acked-by: WANG Cong <xiyou.wangcong@gmail.com>
I already merged similar patches by Jean Sacren, see commits bf5e327 and
4418a2b in kbuild-2.6.git.
Michal
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] kconfig: fix warnings in fgets/fwrite usage
2010-08-17 6:44 ` Michal Marek
@ 2010-08-18 5:36 ` Mike Frysinger
0 siblings, 0 replies; 4+ messages in thread
From: Mike Frysinger @ 2010-08-18 5:36 UTC (permalink / raw)
To: Michal Marek; +Cc: Américo Wang, linux-kbuild, Roman Zippel, linux-kernel
On Tue, Aug 17, 2010 at 02:44, Michal Marek wrote:
> On 17.8.2010 07:46, Américo Wang wrote:
>> On Thu, Aug 12, 2010 at 01:56:19AM -0400, Mike Frysinger wrote:
>>> Add some helper functions that abort on failure, and change the fwrite
>>> and fget calls to use those. This should kill off all the ugly gcc
>>> warnings that some distros emit about ignoring return values due to
>>> usage of warn_unused_result attributes.
>>>
>>> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
>>
>> Looks good to me,
>>
>> Acked-by: WANG Cong <xiyou.wangcong@gmail.com>
>
> I already merged similar patches by Jean Sacren, see commits bf5e327 and
> 4418a2b in kbuild-2.6.git.
guess i should have posted the patches when i wrote them (March). oh
well, as long as it's fixed ;).
-mike
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-08-18 5:37 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-08-12 5:56 [PATCH] kconfig: fix warnings in fgets/fwrite usage Mike Frysinger
2010-08-17 5:46 ` Américo Wang
2010-08-17 6:44 ` Michal Marek
2010-08-18 5:36 ` Mike Frysinger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox