gcc 4.2 warnings
Christian Stimming
stimming at tuhh.de
Fri Oct 5 15:22:53 EDT 2007
Am Donnerstag, 4. Oktober 2007 22:56 schrieb Andrew Sackville-West:
> At jsled's prompting, I'm taking a stab at hacking my way through gcc
> 4.2.1 (debian) warnings. And, at warlord's oh-so-kind prompting, I'm
> actually trying to do something about them.
Patches are always great! Thanks for picking up this work on the newest gcc.
However, in this particular case I think you didn't fix the warning the right
way:
> --- engine/TransLog.c (revision 16547)
> +++ engine/TransLog.c (working copy)
> @@ -273,7 +273,7 @@
> gnc_numeric_denom(amt),
> gnc_numeric_num(val),
> gnc_numeric_denom(val),
> - drecn ? drecn : "");
> + drecn[0] == 0 ? drecn : "");
> }
>
> fprintf (trans_log, "===== END\n");
The whole point of the expression (drecn ? drecn : "" ) is in long form
(drecn != NULL ? drecn : ""), in other words, if the char pointer is
non-NULL, use it, but otherwise use the pointer to an empty string. This is
important for some OS which would crash if a NULL pointer is passed to
printf() and friends, hence they should only get a (non-NULL) empty string.
Your change, however, is a different expression: With your case, if the char
pointer points to a non-empty string, use it, but otherwise use the pointer
to an empty string.
Which points me to the question: Which gcc warning did you try to fix here?
Looking more into context, it turns out drecn is a local char buffer anyway,
hence it can't be NULL anyway. Because of this, here (and only here) you
should replace the expresssion direcly by drecn, i.e.
- drecn ? drecn : "");
+ drecn);
Thanks a lot for starting to fix these warnings!
Christian
More information about the gnucash-devel
mailing list