public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/15744] New: strtod is incorrect on INF/inf case variations in tr_TR.iso88599 locale
@ 2013-07-16  7:57 vincent-srcware at vinc17 dot net
  2014-06-13  9:24 ` [Bug libc/15744] " fweimer at redhat dot com
  2015-08-27 22:16 ` [Bug math/15744] " jsm28 at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: vincent-srcware at vinc17 dot net @ 2013-07-16  7:57 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=15744

            Bug ID: 15744
           Summary: strtod is incorrect on INF/inf case variations in
                    tr_TR.iso88599 locale
           Product: glibc
           Version: 2.17
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
          Assignee: unassigned at sourceware dot org
          Reporter: vincent-srcware at vinc17 dot net
                CC: drepper.fsp at gmail dot com

strtod doesn't recognize some "INF" and "inf" case variations in the
tr_TR.iso88599 locale, e.g. "ınf" and "İNF", due to the dotless "i" and the "I"
with dot in Turkish. The C99 standard says (and it seems that this hasn't be
modified in C11):

    7.20.1.3 The strtod, strtof, and strtold functions
[...]
 3  The expected form of the subject sequence is an optional plus or minus
    sign, then one of the following:
    — a nonempty sequence of decimal digits optionally containing a
      decimal-point character, then an optional exponent part as defined
      in 6.4.4.2;
    — a 0x or 0X, then a nonempty sequence of hexadecimal digits
      optionally containing a decimal-point character, then an optional
      binary exponent part as defined in 6.4.4.2;
    — INF or INFINITY, ignoring case
    — NAN or NAN(n-char-sequence_opt), ignoring case in the NAN part,
[...]
 5  In other than the "C" locale, additional locale-specific subject
    sequence forms may be accepted.

Note that since strtod is locale sensitive (as confirmed in the comments of bug
7021), the "ignoring case" needs to take the current locale into account.

Testcase:

#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <ctype.h>
#include <string.h>
#include <strings.h>

#define STRINGIFY(S) #S
#define MAKE_STR(S) STRINGIFY(S)

#define NUMD 1.67111104753282335
#define NUMS MAKE_STR(NUMD)

void stest (const char *buffer, const char *prefix)
{
  char *endptr;
  double x;

  x = strtod (buffer, &endptr);
  printf ("  %sstrtod(\"%s\",endptr) = %f%s\n", prefix,
          buffer, x, *endptr ? " (endptr error)" : "");
}

int main (int argc, char **argv)
{
  int i, j, k;
  double d = NUMD;
  double inf = 1.0 / 0.0;
  char *infs[] = { "INF", "inf" };
  char buffer[64], prefix[6];

  if (setlocale (LC_ALL, "") == NULL)
    {
      fprintf (stderr, "locale-test: can't set locales\n");
      exit (EXIT_FAILURE);
    }

  printf ("* Output:\n  d = " NUMS " (string)\n");
  printf ("  d = %f (in decimal, %%f format)\n", d);
  printf ("  Infinity: %f\n", inf);
  printf ("* Input:\n");
  strcpy (buffer, NUMS);
  stest (buffer, "");
  sprintf (buffer, "%f", d);
  stest (buffer, "");
  for (i = 0; i < 2; i++)
    for (j = 0; j < 4; j++)
      {
        for (k = 0; k < 3; k++)
          {
            buffer[k] = infs[i][k];
            if (j > k)
              buffer[k] = (i ? toupper : tolower)(buffer[k]);
          }
        buffer[3] = '\0';
        sprintf (prefix, "[%d%d] ",
                 !strcasecmp (buffer, "INF"),
                 !strcasecmp (buffer, "inf"));
        stest (buffer, prefix);
      }

  for (i = 1; i < argc; i++)
    {
      double x;
      char *end;

      x = strtod (argv[i], &end);
      printf ("Argument %d: ", i);
      if (*end == '\0')
        printf ("%.17g\n", x);
      else
        printf ("error\n");
    }

  return 0;
}

It can be tested by running it under the tr_TR.iso88599 locale directly (if the
terminal uses the associated fonts), or with:

  LC_ALL=tr_TR.iso88599 ./locale-test | iconv -f iso88599

from any UTF8-based locales. I get:

* Output:
  d = 1.67111104753282335 (string)
  d = 1,671111 (in decimal, %f format)
  Infinity: inf
* Input:
  strtod("1.67111104753282335",endptr) = 1,000000 (endptr error)
  strtod("1,671111",endptr) = 1,671111
  [11] strtod("INF",endptr) = inf
  [00] strtod("ıNF",endptr) = 0,000000 (endptr error)
  [00] strtod("ınF",endptr) = 0,000000 (endptr error)
  [00] strtod("ınf",endptr) = 0,000000 (endptr error)
  [11] strtod("inf",endptr) = inf
  [00] strtod("İnf",endptr) = 0,000000 (endptr error)
  [00] strtod("İNf",endptr) = 0,000000 (endptr error)
  [00] strtod("İNF",endptr) = 0,000000 (endptr error)

The endptr error for "1.67111104753282335" is normal: with the following line,
it shows that strtod is locale sensitive, as expected. Then the following 8
lines should all succeed, which is not the case here.

Note that the C standard requires to recognize "INF", ignoring case, but says
nothing about "inf". However the IEEE 754-2008 standard mentions "inf"
(ignoring case) and glibc uses "inf" as the output, so that it should also be
recognized, ignoring case.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
>From glibc-bugs-return-19147-listarch-glibc-bugs=sources.redhat.com@sourceware.org Tue Jul 16 10:31:05 2013
Return-Path: <glibc-bugs-return-19147-listarch-glibc-bugs=sources.redhat.com@sourceware.org>
Delivered-To: listarch-glibc-bugs@sources.redhat.com
Received: (qmail 17344 invoked by alias); 16 Jul 2013 10:31:05 -0000
Mailing-List: contact glibc-bugs-help@sourceware.org; run by ezmlm
Precedence: bulk
List-Id: <glibc-bugs.sourceware.org>
List-Subscribe: <mailto:glibc-bugs-subscribe@sourceware.org>
List-Post: <mailto:glibc-bugs@sourceware.org>
List-Help: <mailto:glibc-bugs-help@sourceware.org>, <http://sourceware.org/lists.html#faqs>
Sender: glibc-bugs-owner@sourceware.org
Delivered-To: mailing list glibc-bugs@sourceware.org
Received: (qmail 14929 invoked by uid 48); 16 Jul 2013 10:29:02 -0000
From: "freker at zes dot com" <sourceware-bugzilla@sourceware.org>
To: glibc-bugs@sourceware.org
Subject: [Bug libc/12847] dprintf/vdprintf can cause fork to fail (child process crash)
Date: Tue, 16 Jul 2013 10:31:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: glibc
X-Bugzilla-Component: libc
X-Bugzilla-Version: unspecified
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: freker at zes dot com
X-Bugzilla-Status: REOPENED
X-Bugzilla-Priority: P2
X-Bugzilla-Assigned-To: drepper.fsp at gmail dot com
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields:
Message-ID: <bug-12847-131-msr7n0y0Ud@http.sourceware.org/bugzilla/>
In-Reply-To: <bug-12847-131@http.sourceware.org/bugzilla/>
References: <bug-12847-131@http.sourceware.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://sourceware.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2013-07/txt/msg00088.txt.bz2
Content-length: 813

http://sourceware.org/bugzilla/show_bug.cgi?id\x12847

--- Comment #4 from Frank Reker <freker at zes dot com> ---
OK, I've seen your bugfix in genops.c, however
this does not fix the fork() bug. I suggest
to modify:

nptl/sysdeps/unix/sysv/linux/fork.c
----snip-------
static void
fresetlockfiles (void)
{
  _IO_ITER i;

  for (i = _IO_iter_begin(); i != _IO_iter_end(); i = _IO_iter_next(i))
    _IO_lock_init (*((_IO_lock_t *) _IO_iter_file(i)->_lock));
}
----snap------
to:
----snip-------
static void
fresetlockfiles (void)
{
  _IO_ITER i;

  for (i = _IO_iter_begin(); i != _IO_iter_end(); i = _IO_iter_next(i))
    if (_IO_iter_file(i)->_lock)
       _IO_lock_init (*((_IO_lock_t *) _IO_iter_file(i)->_lock));
}
----snap------

--
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug libc/15744] strtod is incorrect on INF/inf case variations in tr_TR.iso88599 locale
  2013-07-16  7:57 [Bug libc/15744] New: strtod is incorrect on INF/inf case variations in tr_TR.iso88599 locale vincent-srcware at vinc17 dot net
@ 2014-06-13  9:24 ` fweimer at redhat dot com
  2015-08-27 22:16 ` [Bug math/15744] " jsm28 at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: fweimer at redhat dot com @ 2014-06-13  9:24 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=15744

Florian Weimer <fweimer at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
              Flags|                            |security-

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug math/15744] strtod is incorrect on INF/inf case variations in tr_TR.iso88599 locale
  2013-07-16  7:57 [Bug libc/15744] New: strtod is incorrect on INF/inf case variations in tr_TR.iso88599 locale vincent-srcware at vinc17 dot net
  2014-06-13  9:24 ` [Bug libc/15744] " fweimer at redhat dot com
@ 2015-08-27 22:16 ` jsm28 at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: jsm28 at gcc dot gnu.org @ 2015-08-27 22:16 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=15744

Joseph Myers <jsm28 at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|libc                        |math

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-08-27 22:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-16  7:57 [Bug libc/15744] New: strtod is incorrect on INF/inf case variations in tr_TR.iso88599 locale vincent-srcware at vinc17 dot net
2014-06-13  9:24 ` [Bug libc/15744] " fweimer at redhat dot com
2015-08-27 22:16 ` [Bug math/15744] " jsm28 at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).