Bugzilla will be upgraded to version 5.0 on a still to be determined date in the near future. The original upgrade date has been delayed.
Bug 50723 - strtod does not fully scan
strtod does not fully scan
Product: Red Hat Linux
Classification: Retired
Component: glibc (Show other bugs)
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
Aaron Brown
Depends On:
  Show dependency treegraph
Reported: 2001-08-02 12:28 EDT by Trevin Beattie
Modified: 2016-11-24 10:24 EST (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2006-08-04 16:35:08 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

External Trackers
Tracker ID Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2001:121 normal SHIPPED_LIVE GNU C Library bugfix update 2001-10-04 00:00:00 EDT

  None (edit)
Description Trevin Beattie 2001-08-02 12:28:41 EDT
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:

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" };

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);
      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
Comment 1 Jakub Jelinek 2001-08-06 13:10:46 EDT
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 16:35:08 EDT
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.