* [PATCH iproute2 0/2] Fix compiler-errors with gcc 4.7.3 @ 2013-07-20 19:58 Christoph Paasch 2013-07-20 19:58 ` [PATCH iproute2 1/2] ss: Fix compiler errors of unused return-values Christoph Paasch 2013-07-20 19:58 ` [PATCH iproute2 2/2] lnstat: " Christoph Paasch 0 siblings, 2 replies; 9+ messages in thread From: Christoph Paasch @ 2013-07-20 19:58 UTC (permalink / raw) To: Stephen Hemminger; +Cc: netdev gcc complains about unused return-values in ss.c and lnstat_util.c In ss, upon the calls to fscanf, I added an empty if-statement to suppress the compiler-error. Admittedly not a very neat solution, but we can't do anything more here. If you want me to handle the fscanf-case differently, let me know. Christoph Paasch (2): ss: Fix compiler errors of unused return-values lnstat: Fix compiler errors of unused return-values misc/lnstat_util.c | 12 ++++++++---- misc/ss.c | 30 +++++++++++++++++++++--------- 2 files changed, 29 insertions(+), 13 deletions(-) -- 1.8.1.2 ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH iproute2 1/2] ss: Fix compiler errors of unused return-values 2013-07-20 19:58 [PATCH iproute2 0/2] Fix compiler-errors with gcc 4.7.3 Christoph Paasch @ 2013-07-20 19:58 ` Christoph Paasch 2013-07-22 14:54 ` Stephen Hemminger 2013-07-22 15:38 ` Eric Dumazet 2013-07-20 19:58 ` [PATCH iproute2 2/2] lnstat: " Christoph Paasch 1 sibling, 2 replies; 9+ messages in thread From: Christoph Paasch @ 2013-07-20 19:58 UTC (permalink / raw) To: Stephen Hemminger; +Cc: netdev Many errors when compiling with gcc 4.7.3 about unused return-values upon the calls to fgets and fscanf: ss.c: In function ‘user_ent_hash_build’: ss.c:305:12: error: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Werror=unused-result] ss.c: In function ‘get_slabstat’: ss.c:387:7: error: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Werror=unused-result] ss.c: In function ‘init_service_resolver’: ss.c:511:8: error: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Werror=unused-result] ss.c: In function ‘run_ssfilter’: ss.c:728:11: error: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Werror=unused-result] ss.c: In function ‘is_ephemeral’: ss.c:550:10: error: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Werror=unused-result] ss.c: In function ‘netlink_show’: ss.c:2836:7: error: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Werror=unused-result] ss.c: In function ‘packet_show’: ss.c:2630:7: error: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Werror=unused-result] ss.c: In function ‘unix_show’: ss.c:2364:7: error: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Werror=unused-result] cc1: all warnings being treated as errors make[1]: *** [ss.o] Error 1 make[1]: Leaving directory `/home/christoph/workspace/linux/iproute2/misc' make: *** [all] Error 2 For the calls to fscanf we can't really do anything about it, and just do an empty if-statement to make the compiler happy. Signed-off-by: Christoph Paasch <christoph.paasch@uclouvain.be> --- misc/ss.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/misc/ss.c b/misc/ss.c index c0369f1..0f71108 100644 --- a/misc/ss.c +++ b/misc/ss.c @@ -302,7 +302,7 @@ static void user_ent_hash_build(void) snprintf(tmp, sizeof(tmp), "%s/%d/stat", root, pid); if ((fp = fopen(tmp, "r")) != NULL) { - fscanf(fp, "%*d (%[^)])", process); + if (fscanf(fp, "%*d (%[^)])", process) == EOF); fclose(fp); } } @@ -384,7 +384,10 @@ static int get_slabstat(struct slabstat *s) cnt = sizeof(*s)/sizeof(int); - fgets(buf, sizeof(buf), fp); + if (!fgets(buf, sizeof(buf), fp)) { + fclose(fp); + return -1; + } while(fgets(buf, sizeof(buf), fp) != NULL) { int i; for (i=0; i<sizeof(slabstat_ids)/sizeof(slabstat_ids[0]); i++) { @@ -508,7 +511,10 @@ static void init_service_resolver(void) char buf[128]; FILE *fp = popen("/usr/sbin/rpcinfo -p 2>/dev/null", "r"); if (fp) { - fgets(buf, sizeof(buf), fp); + if (!fgets(buf, sizeof(buf), fp)) { + pclose(fp); + return; + } while (fgets(buf, sizeof(buf), fp) != NULL) { unsigned int progn, port; char proto[128], prog[128]; @@ -547,8 +553,7 @@ static int is_ephemeral(int port) if (!ip_local_port_min) { FILE *f = ephemeral_ports_open(); if (f) { - fscanf(f, "%d %d", - &ip_local_port_min, &ip_local_port_max); + if (fscanf(f, "%d %d", &ip_local_port_min, &ip_local_port_max) == EOF); fclose(f); } else { ip_local_port_min = 1024; @@ -725,7 +730,7 @@ static int run_ssfilter(struct ssfilter *f, struct tcpstat *s) if (!low) { FILE *fp = ephemeral_ports_open(); if (fp) { - fscanf(fp, "%d%d", &low, &high); + if (fscanf(fp, "%d%d", &low, &high) == EOF); fclose(fp); } } @@ -2361,7 +2366,10 @@ static int unix_show(struct filter *f) if ((fp = net_unix_open()) == NULL) return -1; - fgets(buf, sizeof(buf)-1, fp); + if (!fgets(buf, sizeof(buf)-1, fp)) { + fclose(fp); + return -1; + } if (memcmp(buf, "Peer", 4) == 0) newformat = 1; @@ -2627,7 +2635,10 @@ static int packet_show(struct filter *f) if ((fp = net_packet_open()) == NULL) return -1; - fgets(buf, sizeof(buf)-1, fp); + if (!fgets(buf, sizeof(buf)-1, fp)) { + fclose(fp); + return -1; + } while (fgets(buf, sizeof(buf)-1, fp)) { sscanf(buf, "%llx %*d %d %x %d %d %u %u %u", @@ -2833,7 +2844,8 @@ static int netlink_show(struct filter *f) if ((fp = net_netlink_open()) == NULL) return -1; - fgets(buf, sizeof(buf)-1, fp); + if (!fgets(buf, sizeof(buf)-1, fp)) + return -1; while (fgets(buf, sizeof(buf)-1, fp)) { sscanf(buf, "%llx %d %d %x %d %d %llx %d", -- 1.8.1.2 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH iproute2 1/2] ss: Fix compiler errors of unused return-values 2013-07-20 19:58 ` [PATCH iproute2 1/2] ss: Fix compiler errors of unused return-values Christoph Paasch @ 2013-07-22 14:54 ` Stephen Hemminger 2013-07-22 15:06 ` Denis Kirjanov 2013-07-22 15:14 ` Christoph Paasch 2013-07-22 15:38 ` Eric Dumazet 1 sibling, 2 replies; 9+ messages in thread From: Stephen Hemminger @ 2013-07-22 14:54 UTC (permalink / raw) To: Christoph Paasch; +Cc: netdev On Sat, 20 Jul 2013 21:58:17 +0200 Christoph Paasch <christoph.paasch@uclouvain.be> wrote: > Many errors when compiling with gcc 4.7.3 about unused return-values > upon the calls to fgets and fscanf: > > ss.c: In function ‘user_ent_hash_build’: > ss.c:305:12: error: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Werror=unused-result] > ss.c: In function ‘get_slabstat’: > ss.c:387:7: error: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Werror=unused-result] > ss.c: In function ‘init_service_resolver’: > ss.c:511:8: error: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Werror=unused-result] > ss.c: In function ‘run_ssfilter’: > ss.c:728:11: error: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Werror=unused-result] > ss.c: In function ‘is_ephemeral’: > ss.c:550:10: error: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Werror=unused-result] > ss.c: In function ‘netlink_show’: > ss.c:2836:7: error: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Werror=unused-result] > ss.c: In function ‘packet_show’: > ss.c:2630:7: error: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Werror=unused-result] > ss.c: In function ‘unix_show’: > ss.c:2364:7: error: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Werror=unused-result] > cc1: all warnings being treated as errors > make[1]: *** [ss.o] Error 1 > make[1]: Leaving directory `/home/christoph/workspace/linux/iproute2/misc' > make: *** [all] Error 2 > > For the calls to fscanf we can't really do anything about it, and just > do an empty if-statement to make the compiler happy. > > I would prefer an error message rather than silently exiting. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH iproute2 1/2] ss: Fix compiler errors of unused return-values 2013-07-22 14:54 ` Stephen Hemminger @ 2013-07-22 15:06 ` Denis Kirjanov 2013-07-22 15:35 ` Stephen Hemminger 2013-07-22 15:14 ` Christoph Paasch 1 sibling, 1 reply; 9+ messages in thread From: Denis Kirjanov @ 2013-07-22 15:06 UTC (permalink / raw) To: Stephen Hemminger; +Cc: Christoph Paasch, netdev Do we need the -Werror at all? I've found a similar discussion regarding building wil6210 driver with the same issue On 7/22/13, Stephen Hemminger <stephen@networkplumber.org> wrote: > On Sat, 20 Jul 2013 21:58:17 +0200 > Christoph Paasch <christoph.paasch@uclouvain.be> wrote: > >> Many errors when compiling with gcc 4.7.3 about unused return-values >> upon the calls to fgets and fscanf: >> >> ss.c: In function ‘user_ent_hash_build’: >> ss.c:305:12: error: ignoring return value of ‘fscanf’, declared with >> attribute warn_unused_result [-Werror=unused-result] >> ss.c: In function ‘get_slabstat’: >> ss.c:387:7: error: ignoring return value of ‘fgets’, declared with >> attribute warn_unused_result [-Werror=unused-result] >> ss.c: In function ‘init_service_resolver’: >> ss.c:511:8: error: ignoring return value of ‘fgets’, declared with >> attribute warn_unused_result [-Werror=unused-result] >> ss.c: In function ‘run_ssfilter’: >> ss.c:728:11: error: ignoring return value of ‘fscanf’, declared with >> attribute warn_unused_result [-Werror=unused-result] >> ss.c: In function ‘is_ephemeral’: >> ss.c:550:10: error: ignoring return value of ‘fscanf’, declared with >> attribute warn_unused_result [-Werror=unused-result] >> ss.c: In function ‘netlink_show’: >> ss.c:2836:7: error: ignoring return value of ‘fgets’, declared with >> attribute warn_unused_result [-Werror=unused-result] >> ss.c: In function ‘packet_show’: >> ss.c:2630:7: error: ignoring return value of ‘fgets’, declared with >> attribute warn_unused_result [-Werror=unused-result] >> ss.c: In function ‘unix_show’: >> ss.c:2364:7: error: ignoring return value of ‘fgets’, declared with >> attribute warn_unused_result [-Werror=unused-result] >> cc1: all warnings being treated as errors >> make[1]: *** [ss.o] Error 1 >> make[1]: Leaving directory >> `/home/christoph/workspace/linux/iproute2/misc' >> make: *** [all] Error 2 >> >> For the calls to fscanf we can't really do anything about it, and just >> do an empty if-statement to make the compiler happy. >> >> > > I would prefer an error message rather than silently exiting. > -- > To unsubscribe from this list: send the line "unsubscribe netdev" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > -- Regards, Denis ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH iproute2 1/2] ss: Fix compiler errors of unused return-values 2013-07-22 15:06 ` Denis Kirjanov @ 2013-07-22 15:35 ` Stephen Hemminger 0 siblings, 0 replies; 9+ messages in thread From: Stephen Hemminger @ 2013-07-22 15:35 UTC (permalink / raw) To: Denis Kirjanov; +Cc: Christoph Paasch, netdev On Mon, 22 Jul 2013 19:06:11 +0400 Denis Kirjanov <kirjanov@gmail.com> wrote: > Do we need the -Werror at all? I've found a similar discussion > regarding building wil6210 driver with the same issue I put Werror in because it stops people from adding new things that have warnings. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH iproute2 1/2] ss: Fix compiler errors of unused return-values 2013-07-22 14:54 ` Stephen Hemminger 2013-07-22 15:06 ` Denis Kirjanov @ 2013-07-22 15:14 ` Christoph Paasch 1 sibling, 0 replies; 9+ messages in thread From: Christoph Paasch @ 2013-07-22 15:14 UTC (permalink / raw) To: Stephen Hemminger; +Cc: netdev On 22/07/13 - 07:54:10, Stephen Hemminger wrote: > On Sat, 20 Jul 2013 21:58:17 +0200 > Christoph Paasch <christoph.paasch@uclouvain.be> wrote: > > > Many errors when compiling with gcc 4.7.3 about unused return-values > > upon the calls to fgets and fscanf: > > > > ss.c: In function ‘user_ent_hash_build’: > > ss.c:305:12: error: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Werror=unused-result] > > ss.c: In function ‘get_slabstat’: > > ss.c:387:7: error: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Werror=unused-result] > > ss.c: In function ‘init_service_resolver’: > > ss.c:511:8: error: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Werror=unused-result] > > ss.c: In function ‘run_ssfilter’: > > ss.c:728:11: error: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Werror=unused-result] > > ss.c: In function ‘is_ephemeral’: > > ss.c:550:10: error: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Werror=unused-result] > > ss.c: In function ‘netlink_show’: > > ss.c:2836:7: error: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Werror=unused-result] > > ss.c: In function ‘packet_show’: > > ss.c:2630:7: error: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Werror=unused-result] > > ss.c: In function ‘unix_show’: > > ss.c:2364:7: error: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Werror=unused-result] > > cc1: all warnings being treated as errors > > make[1]: *** [ss.o] Error 1 > > make[1]: Leaving directory `/home/christoph/workspace/linux/iproute2/misc' > > make: *** [all] Error 2 > > > > For the calls to fscanf we can't really do anything about it, and just > > do an empty if-statement to make the compiler happy. > > > > > > I would prefer an error message rather than silently exiting. Ok, I will resubmit. Cheers, Christoph ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH iproute2 1/2] ss: Fix compiler errors of unused return-values 2013-07-20 19:58 ` [PATCH iproute2 1/2] ss: Fix compiler errors of unused return-values Christoph Paasch 2013-07-22 14:54 ` Stephen Hemminger @ 2013-07-22 15:38 ` Eric Dumazet 2013-07-22 17:26 ` Ben Hutchings 1 sibling, 1 reply; 9+ messages in thread From: Eric Dumazet @ 2013-07-22 15:38 UTC (permalink / raw) To: Christoph Paasch; +Cc: Stephen Hemminger, netdev On Sat, 2013-07-20 at 21:58 +0200, Christoph Paasch wrote: > Many errors when compiling with gcc 4.7.3 about unused return-values > upon the calls to fgets and fscanf: > > For the calls to fscanf we can't really do anything about it, and just > do an empty if-statement to make the compiler happy. > > Signed-off-by: Christoph Paasch <christoph.paasch@uclouvain.be> > --- > misc/ss.c | 30 +++++++++++++++++++++--------- > 1 file changed, 21 insertions(+), 9 deletions(-) > > diff --git a/misc/ss.c b/misc/ss.c > index c0369f1..0f71108 100644 > --- a/misc/ss.c > +++ b/misc/ss.c > @@ -302,7 +302,7 @@ static void user_ent_hash_build(void) > > snprintf(tmp, sizeof(tmp), "%s/%d/stat", root, pid); > if ((fp = fopen(tmp, "r")) != NULL) { > - fscanf(fp, "%*d (%[^)])", process); > + if (fscanf(fp, "%*d (%[^)])", process) == EOF); This is really ugly :( ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH iproute2 1/2] ss: Fix compiler errors of unused return-values 2013-07-22 15:38 ` Eric Dumazet @ 2013-07-22 17:26 ` Ben Hutchings 0 siblings, 0 replies; 9+ messages in thread From: Ben Hutchings @ 2013-07-22 17:26 UTC (permalink / raw) To: Eric Dumazet; +Cc: Christoph Paasch, Stephen Hemminger, netdev On Mon, 2013-07-22 at 08:38 -0700, Eric Dumazet wrote: > On Sat, 2013-07-20 at 21:58 +0200, Christoph Paasch wrote: > > Many errors when compiling with gcc 4.7.3 about unused return-values > > upon the calls to fgets and fscanf: > > > > > For the calls to fscanf we can't really do anything about it, and just > > do an empty if-statement to make the compiler happy. > > > > Signed-off-by: Christoph Paasch <christoph.paasch@uclouvain.be> > > --- > > misc/ss.c | 30 +++++++++++++++++++++--------- > > 1 file changed, 21 insertions(+), 9 deletions(-) > > > > diff --git a/misc/ss.c b/misc/ss.c > > index c0369f1..0f71108 100644 > > --- a/misc/ss.c > > +++ b/misc/ss.c > > @@ -302,7 +302,7 @@ static void user_ent_hash_build(void) > > > > snprintf(tmp, sizeof(tmp), "%s/%d/stat", root, pid); > > if ((fp = fopen(tmp, "r")) != NULL) { > > - fscanf(fp, "%*d (%[^)])", process); > > + if (fscanf(fp, "%*d (%[^)])", process) == EOF); > > This is really ugly :( It is. And gcc doesn't accept casting to void to suppress the warning. Maybe add a wrapper fscanf_with_output_already_set_to_default()? ;-) Or do what glibc expects and set the defaults only when fscanf() reads less than we wanted: switch (fscanf(p, "...", &foo, &bar, ...)) { case EOF: case 0: foo = ...; case 1: bar = ...; ... } Ben. -- Ben Hutchings, Staff Engineer, Solarflare Not speaking for my employer; that's the marketing department's job. They asked us to note that Solarflare product names are trademarked. ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH iproute2 2/2] lnstat: Fix compiler errors of unused return-values 2013-07-20 19:58 [PATCH iproute2 0/2] Fix compiler-errors with gcc 4.7.3 Christoph Paasch 2013-07-20 19:58 ` [PATCH iproute2 1/2] ss: Fix compiler errors of unused return-values Christoph Paasch @ 2013-07-20 19:58 ` Christoph Paasch 1 sibling, 0 replies; 9+ messages in thread From: Christoph Paasch @ 2013-07-20 19:58 UTC (permalink / raw) To: Stephen Hemminger; +Cc: netdev Many errors when compiling with gcc 4.7.3 about unused return-values upon the calls to fgets: lnstat_util.c: In function ‘lnstat_scan_fields’: lnstat_util.c:145:7: error: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Werror=unused-result] lnstat_util.c: In function ‘lnstat_update’: lnstat_util.c:97:10: error: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Werror=unused-result] lnstat_util.c:111:9: error: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Werror=unused-result] lnstat_util.c: In function ‘scan_lines’: lnstat_util.c:52:8: error: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Werror=unused-result] cc1: all warnings being treated as errors make[1]: *** [lnstat_util.o] Error 1 make[1]: Leaving directory `/home/christoph/workspace/linux/iproute2/misc' make: *** [all] Error 2 Signed-off-by: Christoph Paasch <christoph.paasch@uclouvain.be> --- misc/lnstat_util.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/misc/lnstat_util.c b/misc/lnstat_util.c index 9492baf..103c05d 100644 --- a/misc/lnstat_util.c +++ b/misc/lnstat_util.c @@ -49,7 +49,8 @@ static int scan_lines(struct lnstat_file *lf, int i) num_lines++; - fgets(buf, sizeof(buf)-1, lf->fp); + if (!fgets(buf, sizeof(buf)-1, lf->fp)) + return num_lines; gettimeofday(&lf->last_read, NULL); for (j = 0; j < lf->num_fields; j++) { @@ -94,7 +95,8 @@ int lnstat_update(struct lnstat_file *lnstat_files) rewind(lf->fp); if (!lf->compat) { /* skip first line */ - fgets(buf, sizeof(buf)-1, lf->fp); + if (!fgets(buf, sizeof(buf)-1, lf->fp)) + return 0; } scan_lines(lf, 1); @@ -108,7 +110,8 @@ int lnstat_update(struct lnstat_file *lnstat_files) } rewind(lf->fp); - fgets(buf, sizeof(buf)-1, lf->fp); + if (!fgets(buf, sizeof(buf)-1, lf->fp)) + return 0; scan_lines(lf, 0); } } @@ -142,7 +145,8 @@ static int lnstat_scan_fields(struct lnstat_file *lf) char buf[FGETS_BUF_SIZE]; rewind(lf->fp); - fgets(buf, sizeof(buf)-1, lf->fp); + if (!fgets(buf, sizeof(buf)-1, lf->fp)) + return -1; return __lnstat_scan_fields(lf, buf); } -- 1.8.1.2 ^ permalink raw reply related [flat|nested] 9+ messages in thread
end of thread, other threads:[~2013-07-22 17:26 UTC | newest] Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2013-07-20 19:58 [PATCH iproute2 0/2] Fix compiler-errors with gcc 4.7.3 Christoph Paasch 2013-07-20 19:58 ` [PATCH iproute2 1/2] ss: Fix compiler errors of unused return-values Christoph Paasch 2013-07-22 14:54 ` Stephen Hemminger 2013-07-22 15:06 ` Denis Kirjanov 2013-07-22 15:35 ` Stephen Hemminger 2013-07-22 15:14 ` Christoph Paasch 2013-07-22 15:38 ` Eric Dumazet 2013-07-22 17:26 ` Ben Hutchings 2013-07-20 19:58 ` [PATCH iproute2 2/2] lnstat: " Christoph Paasch
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).