-   Software (
-   -   Opinion about Prime95 compile warnings and -Wno-unused-result (

Explorer09 2014-08-16 15:19

Opinion about Prime95 compile warnings and -Wno-unused-result
I tried to compile mprime 28.5 on Ubuntu (Linux) 14.04 for my own use. However GCC in Ubuntu's default setting generates [I]many[/I] compiler warnings. Although I read the makefile which suggests they can be suppressed by -Wno-unused-result compiler flag, it still makes me curious to know what they're about.

And I found out there are indeed code that I can consider bad practice, and the compiler did the right thing by generating warnings.

One example:
[CODE]../ecm.c: In function ‘ecm_QA’:
../ecm.c:3568:3: warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Wunused-result]
(void) fscanf (fd, "%lf,%lu,%lu,%ld,%lf,%lu,%lu,%lu,%s\n",

[CODE]/* Read a line from the file */
n = 0;
(void) fscanf (fd, "%lf,%lu,%lu,%ld,%lf,%lu,%lu,%lu,%s\n",
&k, &b, &n, &c, &sigma, &B1, &B2_start, &B2_end,
if (n == 0) break;

The code is supposed to parse a file (named 'qa_ecm'), but does not check whether the file can EOF at the middle of the line. The return code of [I]fscanf[/I] can be used to do this, but here it is intentionally ignored.

I think it will be better to rewrite it to something like this:
(EOF at the middle of the line usually means file is corrupt, so return an error that way)
[CODE]int rc;
rc = fscanf (fd, "%lf,%lu,%lu,%ld,%lf,%lu,%lu,%lu,%s\n",
&k, &b, &n, &c, &sigma, &B1, &B2_start, &B2_end,
if (rc < 9) { // Note: (rc != EOF) won't work!
OutputStr (thread_num, "File corrupt.\n");

Fixing all of these can take a lot of time, and I have little to help. But it's a bad idea to suppress there warnings - just keep them on (-Wunused-result) and we can easily spot bugs through them.

All times are UTC. The time now is 05:27.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.