After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 756550 - gtypes.h: Make G_MININTn literals negative
gtypes.h: Make G_MININTn literals negative
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: introspection
unspecified
Other All
: Normal minor
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2015-10-14 05:16 UTC by Mikhail Zabaluev
Modified: 2016-08-16 23:52 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gtypes.h: Make G_MININTn literals negative (1.46 KB, patch)
2015-10-14 05:16 UTC, Mikhail Zabaluev
committed Details | Review

Description Mikhail Zabaluev 2015-10-14 05:16:08 UTC
This is more friendly to the GIR scanner; with previous definitions,
the constant values end up out of range for their stated integer type.
Comment 1 Mikhail Zabaluev 2015-10-14 05:16:12 UTC
Created attachment 313238 [details] [review]
gtypes.h: Make G_MININTn literals negative
Comment 2 Dan Winship 2015-10-14 13:31:49 UTC
Comment on attachment 313238 [details] [review]
gtypes.h: Make G_MININTn literals negative

> 6.3.1.3 Signed and unsigned integers
> 
> 1 When a value with integer type is converted to another integer type
> other than _Bool, if the value can be represented by the new type, it
> is unchanged.
> 
> 2 Otherwise, if the new type is unsigned, the value is converted by
> repeatedly adding or subtracting one more than the maximum value that
> can be represented in the new type until the value is in the range of
> the new type.
> 
> 3 Otherwise, the new type is signed and the value cannot be represented
> in it; either the result is implementation-defined or an implementation-
> defined signal is raised.

So the current code isn't just confusing, it actually depends on undefined behavior. (Funny that neither gcc nor clang warns about this...)

The definition of G_MAXUINT64 is pretty special too... that ought to be using G_GUINT64_CONSTANT rather than making assumptions like that (which don't work with two of the possible definitions of G_GINT64_CONSTANT in configure.ac).
Comment 3 Mikhail Zabaluev 2015-10-15 20:48:54 UTC
Attachment 313238 [details] pushed as 05aafe2 - gtypes.h: Make G_MININTn literals negative
Comment 4 Ole André Vadla Ravnås 2016-08-13 20:52:17 UTC
This results in a warning regression on MSVS 2015:
warning C4146: unary minus operator applied to unsigned type, result still unsigned
Seems like the `0x` prefix implies that the value is unsigned.
Comment 5 Ole André Vadla Ravnås 2016-08-13 21:10:15 UTC
Ah no, the base is obviously irrelevant, this is about the value being out of range. Hmm.
Comment 6 Ole André Vadla Ravnås 2016-08-13 21:19:53 UTC
This is actually only an issue for G_MININT32. The warning is fixed by rewriting it to:

#define G_MININT32	((gint32) (-0x7fffffff - 1))

This is what Microsoft's limits.h does.
Comment 7 Gerald Combs 2016-08-16 23:52:49 UTC
(In reply to Ole André Vadla Ravnås from comment #6)
> This is actually only an issue for G_MININT32. The warning is fixed by
> rewriting it to:
> 
> #define G_MININT32	((gint32) (-0x7fffffff - 1))
> 
> This is what Microsoft's limits.h does.

Can this bug be reopened? I can confirm that 05aafe2 breaks compilation with Visual C++ 2013, and that this change fixes it.