Bug 50724 - scanf does not recognize signed infinities
Summary: scanf does not recognize signed infinities
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:29 UTC by Trevin Beattie
Modified: 2016-11-24 15:12 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2006-08-04 20:27:43 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:29:05 UTC
From Bugzilla Helper:
User-Agent: Mozilla/4.77 [en] (X11; U; Linux 2.4.2-2 i586)

Description of problem:
While all floating-point conversions work for scanning "inf" and "infinity"
(regardless of case), they all fail for "+inf" and "-inf" (and "+infinity"
and "-infinity", regardless of case).

The C standard requires that %a, %e, %f, and %g match an optionally signed
floating-point number, infinity, or NaN, in the same format expected for
the strtod() function.


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:  (long list; here's the summary: 57 tests passed, 105
errors reported)

strtof("inf") passed
sscanf("inf","%a%n",&f) passed
...
sscanf("iNfInItY","%G%n",&f) passed
strtof("+inf") passed
Error: sscanf("+inf","%a%n",&f) returned 0
...
Error: sscanf("-Inf","%G%n",&f) returned 0
Error: strtof("-INFinitY") scanned 4 characters
Error: sscanf("-INFinitY","%a%n",&f) returned 0


Expected Results:  All 162 tests should pass


Additional info:

c.f. WG14/N869 7.19.6.2#12&14, 7.20.1.3#3-4

Comment 1 Jakub Jelinek 2001-08-06 17:09:54 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:27:43 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.