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 767839 - GLib format strings for int64 values don't require "ll" modifier - causes segfault on 32-bit arches
GLib format strings for int64 values don't require "ll" modifier - causes seg...
Status: RESOLVED OBSOLETE
Product: vala
Classification: Core
Component: general
0.32.x
Other Linux
: Normal major
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2016-06-19 11:36 UTC by Michael Gratton
Modified: 2018-05-22 15:36 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Minimal testcase (166 bytes, text/plain)
2016-06-20 06:56 UTC, Michael Gratton
Details

Description Michael Gratton 2016-06-19 11:36:51 UTC
When formatting an int64 value using GLib format strings (e.g. say using GLib.debug), valac is not complaining if the correct length modifier is not set, i.e. "ll".

While valac does not complain about this, gcc does on the translated C file, but that's basically impossible to spot amounts all of the warnings gcc spits out unsless you go looking for it.

For example, valac will compile this fine, without warning:

> int64 x = 0;
> debug("%d", x);

Valac should instead require "%lld" as the format string, as gcc points out.

This will cause programs to segfault on 32-bit arches.
Comment 1 Jürg Billeter 2016-06-19 14:28:24 UTC
With your two lines, valac 0.32.0 doesn't just warn, it reports an error:

> test.vala:3.14-3.14: error: Argument 2: Cannot convert from `int64' to `int'
> 	debug("%d", x);
> 	            ^
> Compilation failed: 1 error(s), 0 warning(s)

Please provide a full test case where this issue can be reproduced.
Comment 2 Michael Gratton 2016-06-20 06:56:51 UTC
Created attachment 330049 [details]
Minimal testcase

Turns out the problem occurs when the format string is formed by concatenating two (or presumably more) strings:

> int64 x = 0;
> debug(" " + "%d", x);

In my case, the format string was rather long and hence split over multiple lines.
Comment 3 Luca Bruno 2016-06-20 08:49:06 UTC
Actually, gcc will also warn when using int64 and %lld. Because on 64bit platforms, %lld is long long while int64 is long. For int64 the correct format is G_INT64_FORMAT.
Comment 4 Jürg Billeter 2016-06-20 10:38:19 UTC
(In reply to Luca Bruno from comment #3)
> Actually, gcc will also warn when using int64 and %lld. Because on 64bit
> platforms, %lld is long long while int64 is long. For int64 the correct
> format is G_INT64_FORMAT.

Yes, however, %lld is safe on all common 32-bit and 64-bit platforms, to my knowledge. It's unfortunate that int64_t is typically defined as long instead of long long on 64-bit systems. People use %ld for 64-bit values because of that even though %lld is more portable.
Comment 5 Michael Gratton 2016-06-21 01:13:26 UTC
Also, it's more concerning that valac doesn't report an error, especially since it leads to crashes on 32bit arches.
Comment 6 GNOME Infrastructure Team 2018-05-22 15:36:34 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/vala/issues/543.