This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
[pedretti@roguewave.com] libc/2072: sscanf fails to correctly parse certain floating point numbers
- To: libc-alpha at sources dot redhat dot com
- Subject: [pedretti@roguewave.com] libc/2072: sscanf fails to correctly parse certain floating point numbers
- From: Andreas Jaeger <aj at suse dot de>
- Date: 07 Feb 2001 09:04:17 +0100
- Cc: pedretti at roguewave dot com
We received the appended bug report. First analysis shows that
strtold is broken. The output of the program is:
ldval = 3.000000, ret = 1
ldval = 0.000000, ret = 1
ldval = 0.000000, errno: Success
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#define _GNU_SOURCE 1
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
int
main (void)
{
long double ldval = 0;
int ret;
ret = sscanf("30000000000000000000.00e-19", "%Lf", &ldval);
printf("ldval = %Lf, ret = %d\n", ldval, ret);
ret = sscanf("300000000000000000000.00e-20", "%Lf", &ldval);
printf("ldval = %Lf, ret = %d\n", ldval, ret);
errno = 0;
ldval = strtold ("300000000000000000000.00e-20", NULL);
printf("ldval = %Lf, errno: %m\n", ldval);
return 0;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Any ideas?
Andreas
Subject: Topics
Topics:
libc/2072: sscanf fails to correctly parse certain floating point numbers
- To: libc-gnats at gnu dot org, gnats-admin at gnu dot org
- Subject: libc/2072: sscanf fails to correctly parse certain floating point numbers
- From: pedretti at roguewave dot com
- Date: Tue, 06 Feb 2001 14:26:18 -0500
>Number: 2072
>Category: libc
>Synopsis: sscanf fails to correctly parse certain floating point numbers
>Confidential: yes
>Severity: serious
>Priority: high
>Responsible: libc-gnats
>State: open
>Quarter:
>Keywords:
>Class: sw-bug
>Submitter-Id: gnatsweb
>Arrival-Date: Tue Feb 06 14:26:17 -0500 2001
>Cases:
>Originator: John A. Pedretti
>Release: GNU C Library stable release version 2.1.1, by Roland McGrath et al.
>Organization:
Rogue Wave Software, Inc
Boulder CO
>Environment:
Linux 2.2.5-15smp #1 SMP Mon Apr 19 22:43:28 EDT 1999 i686 unknown
>Description:
sscanf fails to correctly parse floating point numbers of the form: a digit from 1-9, followed by N occurrences of the digit 0, followed by e-N, where N>20 (i.e., the value of the whole number is equal to the initial digit).
float, double, and long double are all affected, but for different values of N:
float fails for the range 31 <= N <= FLT_MIN_EXP
double fails for the range 180 <= N <= DBL_MIN_EXP
long double fails for the range 20 <= N <= LDBL_MIN_EXP
In most cases, the value scanned in is 0.0, but in some cases it is "inf".
The attached file contains a program that exercises the bug for all meaningful values of N.
>How-To-Repeat:
Example:
#include <stdio.h>
int main() {
long double ldval = 0;
sscanf("30000000000000000000.00e-19", "%Lf", &ldval);
printf("ldval = %Lf\n", ldval);
sscanf("300000000000000000000.00e-20", "%Lf", &ldval);
printf("ldval = %Lf\n", ldval);
}
--- output ---
ldval = 3.000000
ldval = 0.000000
--------------
>Fix:
Unknown
>Unformatted:
--
Andreas Jaeger
SuSE Labs aj@suse.de
private aj@arthur.inka.de
http://www.suse.de/~aj