GNOME Bugzilla – Bug 596730
Signed vs. unsigned comparison in gtkdoc-scangobj.in causing compile errors
Last modified: 2009-09-30 07:03:46 UTC
Created attachment 144260 [details] [review] Patch to cast gint64 to gulong when comparing to G_MAXULONG Over at Xfce we recently noticed that some of our components using gtk-doc to generate API documentation didn't pass make distcheck on our buildbot. The log file can be seen on http://buildbot.xfce.org/core/builders/thunar_on_buildbotD/builds/26/steps/make%20distcheck/logs/stdio, but the essential part is this: cc1: warnings being treated as errors thunarx-scan.c: In function ‘describe_signed_constant’: thunarx-scan.c:884: error: comparison between signed and unsigned Compilation of scanner failed: make[3]: *** [scan-build.stamp] Error 1 I looked at the gtk-doc source code and found out that in gtkdoc-scangobj.in, a gint64 value is compared to G_MAXULONG (which is gulong). I know that our compiler flags are very strict, but still, this can be fixed in gtk-doc easily. Attached is a patch against HEAD that casts the value to gulong when comparing it to G_MAXULONG. We tested this and it works.
This is not resolved yet, but after some discussion on IRC I have to correct some of my comments. G_MAXULONG fits into gint64 but gint64 doesn't fit into gulong. So casting gint64 to gulong is bad. But still, we have a unsigned value (G_MAXULONG) compared to a signed value (the gint64 value). As G_MAXULONG will always fit into gint64, we can probably safely cast it to gint64 and thus, make the comparison value == (gint64) G_MAXULONG instead of the original value == G_MAXULONG The warning (it's just an error because of -Werror, I suppose) can be worked around with gcc by passing -Wno-sign-compare to the compiler. This is what we do for some components which is also why we don't get the error for all of them.
commit 982623eb8931ac6a7b6fb56159d1ed5bfe0543a7 Author: Stefan Kost <ensonic@users.sf.net> Date: Wed Sep 30 09:55:47 2009 +0300 scanobj: fix signedness comparission warnings from gcc. Fixes #596730 Add casts to constants.