c - printf format string lint warning -
i'm stuck fixing ancient code, , here today's issue:
output_file_status = fprintf ( data_file, "%03d%08s%+014.2f%06.3f%", longvalue, charstarvalue, double1, double2 );
lint32 produces: lint32 results in “malformed format string”
1) agree format string can not end in %
sign? don't believe standalone %
has meaning.
2) when either remove trailing %
, or append additional %
, still same warning.
this using oracle pro*c compiler (so charstarvalue (char*)varchar.arr ).
taking piece piece:
"%03d" expects int
. op supplies longvalue
. long
, specifier should "%03ld".
"%08s" expects pointer char
. op supplies charstarvalue
. ok. "0" in specifier undefined behavior %s
. recommend "%8s"
"%+014.2f" expects double
. ok. flags '+', '0' ok.
"%06.3f" expects double
. ok. flags '+', '0' ok.
"%" should have after else behavior undefined. recommend removal or "%%".
to op's 2 points
1 proper format should not end lone %
, may end paired %%
s.
standalone %
introduces "if conversion specification invalid, behavior undefined" c11 7.21.6.1 9.
2 rid of warnings, try "%03ld%8s%+014.2f%06.3f"
.
Comments
Post a Comment