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 704585 - libc printf can give mixed-case strings for NaN and Inf
libc printf can give mixed-case strings for NaN and Inf
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gvariant
2.36.x
Other All
: Normal minor
: ---
Assigned To: Allison Karlitskaya (desrt)
gtkdev
Depends on:
Blocks:
 
 
Reported: 2013-07-19 20:40 UTC by Igor Pashev
Modified: 2013-07-21 15:00 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
proposed patch (938 bytes, patch)
2013-07-19 20:40 UTC, Igor Pashev
none Details | Review

Description Igor Pashev 2013-07-19 20:40:31 UTC
Created attachment 249658 [details] [review]
proposed patch

This test fails on illumos (aka opensolaris) libc:

glib test (glib/tests/gvariant.c)

3728   /* inf/nan mini test */
3729   {
3730     const gchar *tests[] = { "inf", "-inf", "nan" };
3731     GVariant *value;
3732     gchar *printed;
3733     gint i;
3734
3735     for (i = 0; i < G_N_ELEMENTS (tests); i++)
3736       {
3737         GError *error = NULL;
3738         value = g_variant_parse (NULL, tests[i], NULL, NULL,
&error);
3739         printed = g_variant_print (value, FALSE);
3740         g_assert (g_str_has_prefix (printed, tests[i]));
3741         g_free (printed);
3742         g_variant_unref (value);
3743       }
3744   }

Because libc give mixed-case strings. Here is a test program:
#include <stdlib.h>
#include <stdio.h>
#include <math.h>

#ifndef NAN
#define NAN (atof ("NaN"))
#endif

#ifndef INFINITY
#define INFINITY (atof("Infinity"))
#endif

int main()
{
    double inf = INFINITY;
    double minf = -INFINITY;
    double nan = NAN;
    printf("\"%f\", \"%f\", \"%f\"\n", inf, minf, nan);
    return EXIT_SUCCESS;
}


On linux (glibc):
# ./a.out 
"inf", "-inf", "nan"

On illumos:
$ ./a.out 
"Inf", "-Inf", "NaN"
Comment 1 Colin Walters 2013-07-19 22:24:59 UTC
Thanks, I turned this into "git format-patch" style, and I also added a comment in the code.

https://git.gnome.org/browse/glib/commit/?id=dc87c453fbdcf568990c0e7587fa4607f5e148b9
Comment 2 Igor Pashev 2013-07-21 15:00:59 UTC
P. S.

It's all solaris bullshit:

http://lists.gnu.org/archive/html/autoconf/2010-12/msg00059.html


===============================================
POSIX:2008 says that the output should be "inf".

$ /opt/solstudio12.2/bin/cc foo.c && ./a.out
Inf
$ nm a.out | grep values
[34]    |         0|       0|FILE |LOCL |0    |ABS    |values-Xa.c

$ /opt/solstudio12.2/bin/cc -xc99=all foo.c && ./a.out
inf
$ nm a.out | grep values
[34]    |         0|       0|FILE |LOCL |0    |ABS    |values-Xa.c
[36]    |         0|       0|FILE |LOCL |0    |ABS    |values-xpg6.c

..........................
The right way to distinguish desired standards conformance, in a way
that works fine with libraries, is through preprocessor defines
(such as __EXTENSIONS__, _FILE_OFFSET_BITS, etc.). This technique is
used in Solaris in some places (ttyname_r, getlogin_r, sysconf, putmsg
etc.); no idea why the implementors went the wrong way for printf and
other functions.
===============================================