georgemarselis / openlava-macosx

Automatically exported from code.google.com/p/openlava-macosx
GNU General Public License v2.0
1 stars 0 forks source link

lshosts.c:142:8: error: format not a string literal, argument types not checked #236

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Problem:

lshosts.c: In function 'print_long':
lshosts.c:142:8: error: format not a string literal, argument types not checked 
[-Werror=format-nonliteral]
        sprintf (tmpbuf, newFmt, indxnames[i]);
        ^
compilation terminated due to -Wfatal-errors.
cc1: all warnings being treated as errors

Problem Description:

148           sprintf (newFmt, "%s%d%s", "%", newIndexLen + 1, "s");
149           sprintf (tmpbuf, newFmt, indxnames[i]);

the second sprintf does not have a string literal as an argument;
compiler cannot typecheck. compilation fails because -Werror=format-nonliteral

The original author was trying to do a double for loop, in order to print all
the characteristics of all the host, as it is evident in struct indexFmt :

 49 struct indexFmt fmt1[] = {
 50   {"r15s", "%6s", "*%4.1f", "%5.1f", 1.0},
 51   {"r1m", "%6s", "*%4.1f", "%5.1f", 1.0},
 52   {"r15m", "%6s", "*%4.1f", "%5.1f", 1.0},
 53   {"ut", "%5s", "*%3.0f%%", "%3.0f%%", 100.0},
 54   {"pg", "%6s", "*%4.1f", "%4.1f", 1.0},
 55   {"io", "%6s", "*%4.0f", "%4.0f", 1.0},
 56   {"ls", "%5s", "*%2.0f", "%2.0f", 1.0},
 57   {"it", "%5s", "*%3.0f", "%4.0f", 1.0},
 58   {"tmp", "%6s", "*%4.0fM", "%4.0fM", 1.0},
 59   {"swp", "%6s", "*%3.0fM", "%4.0fM", 1.0},
 60   {"mem", "%6s", "*%3.0fM", "%4.0fM", 1.0},
 61   {"dflt", "%7s", "*%6.1f", "%6.1f", 1.0},
 62   {NULL, "%7s", "*%6.1f", " %6.1f", 1.0}
 63 }, *fmt;

How to it: 

Re-write print_long; unroll struct indexFmt, into individual sprintf statemnts

or

prepare a buffer with the output beforehand, print.

Original issue reported on code.google.com by geo...@marsel.is on 12 Aug 2014 at 11:20

GoogleCodeExporter commented 9 years ago
> The original author was trying to avoid having a double for loop

or so it seems.

Original comment by geo...@marsel.is on 12 Aug 2014 at 1:43