Bug 50723 - strtod does not fully scan
Summary: strtod does not fully scan
Keywords:
Status: CLOSED NEXTRELEASE
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: glibc
Version: 7.1
Hardware: i386
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Aaron Brown
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2001-08-02 16:28 UTC by Trevin Beattie
Modified: 2016-11-24 15:24 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2006-08-04 20:35:08 UTC
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2001:121 0 normal SHIPPED_LIVE GNU C Library bugfix update 2001-10-04 04:00:00 UTC

Description Trevin Beattie 2001-08-02 16:28:41 UTC
From Bugzilla Helper:
User-Agent: Mozilla/4.77 [en] (X11; U; Linux 2.4.2-2 i586)

Description of problem:
When using strtod() and friends on the input string "infinity" (preceded by
an optional plus or minus sign), it only scans as far as "inf".  Although
the conversion is valid in either case, the pointer stored in *endptr will
be incorrect.

The standard states that the subject sequence is defined as the *longest*
initial sequence of the input string that is of the expected form.


How reproducible:
Always

Steps to Reproduce:
Compile and run the following program:

#include <stdio.h>
#define __USE_ISOC99 1
#include <math.h>
#include <stdlib.h>

const char *test_strings[] = {
  "inf", "INF", "infinity", "INFINITY", "Inf", "iNfInItY",
  "+inf", "+INF", "+infinity", "+INFINITY", "+Inf", "+InFiNiTy",
  "-inf", "-INF", "-infinity", "-INFINITY", "-Inf", "-INFinitY",
};

const char *test_formats[] = { "%a%n", "%e%n", "%f%n", "%g%n",
			       "%A%n", "%E%n", "%F%n", "%G%n" };

int
main ()
{
  int i, j, l, n;
  float f;
  char *endp;

  for (i = 0; i < sizeof (test_strings) / sizeof (test_strings[0]); i++) {
    f = strtof (test_strings[i], &endp);
    if (*endp)
      fprintf (stderr, "Error: strtof(\"%s\") scanned %d characters\n",
	       test_strings[i], endp - &test_strings[i][0]);
    else if (!isinf(f))
      fprintf (stderr, "Error: strtof(\"%s\") returned %g\n",
	       test_strings[i], f);
    else
      fprintf (stderr, "strtof(\"%s\") passed\n", test_strings[i]);

    for (j = 0; j < sizeof (test_formats) / sizeof (test_formats[0]); j++)
{
      f = 0.0F;
      l = -1;
      n = sscanf (test_strings[i], test_formats[j], &f, &l);
      if (n < 1)
	fprintf (stderr, "Error: sscanf(\"%s\",\"%s\",&f) returned %d\n",
		 test_strings[i], test_formats[j], n);
      if ((l >= 0) && test_strings[i][l])
	fprintf (stderr,
		 "Error: sscanf(\"%s\",\"%s\",&f) scanned %d characters\n",
		 test_strings[i], test_formats[j], l);
      if (!isinf (f) && ((n >= 1) || (f != 0.0F)))
	fprintf (stderr, "Error: sscanf(\"%s\",\"%s\",&f) stored %g\n",
		 test_strings[i], test_formats[j], f);
      if ((n >= 1) && isinf (f))
	fprintf (stderr, "sscanf(\"%s\",\"%s\",&f) passed\n",
		 test_strings[i], test_formats[j]);
    }
  }
}


Actual Results:  (sscanf test results omitted:)

strtof("inf") passed
strtof("INF") passed
Error: strtof("infinity") scanned 3 characters
Error: strtof("INFINITY") scanned 3 characters
strtof("Inf") passed
Error: strtof("iNfInItY") scanned 3 characters
strtof("+inf") passed
strtof("+INF") passed
Error: strtof("+infinity") scanned 4 characters
Error: strtof("+INFINITY") scanned 4 characters
strtof("+Inf") passed
Error: strtof("+InFiNiTy") scanned 4 characters
strtof("-inf") passed
strtof("-INF") passed
Error: strtof("-infinity") scanned 4 characters
Error: strtof("-INFINITY") scanned 4 characters
strtof("-Inf") passed
Error: strtof("-INFinitY") scanned 4 characters


Expected Results:  All 18tests should pass


Additional info:

c.f. WG14/N869 7.20.1.3#3-4

Comment 1 Jakub Jelinek 2001-08-06 17:10:46 UTC
Should be fixed by http://sources.redhat.com/ml/libc-hacker/2001-08/msg00012.html
which will appear in glibc-2.2.4-2.

Comment 2 Bill Nottingham 2006-08-04 20:35:08 UTC
Red Hat Linux and Red Hat Powertools are currently no longer supported by Red
Hat, Inc. In an effort to clean up bugzilla, we are closing all bugs in MODIFIED
state for these products.

However, we do want to make sure that nothing important slips through the
cracks. If, in fact, these issues are not resolved in a current Fedora Core
Release (such as Fedora Core 5), please open a new issues stating so. Thanks.


Note You need to log in before you can comment on or make changes to this bug.