Bug#289264: libc6: scanf() wrong results
Package: libc6
Version: 2.3.2.ds1-20
Severity: normal
scanf() sometimes produces erroneous results (it reads part of the next
line when it shouldn't). See the attached program (which runs correctly
on Solaris 9).
-- System Information:
Debian Release: 3.1
APT prefers unstable
APT policy: (500, 'unstable')
Architecture: i386 (i686)
Kernel: Linux 2.4.27
Locale: LANG=C, LC_CTYPE=en_US.ISO-8859-1 (charmap=ISO-8859-1)
Versions of packages libc6 depends on:
ii libdb1-compat 2.1.3-7 The Berkeley database routines [gl
-- no debconf information
#include <stdio.h>
/*
* This program exhibits a bug with scanf() processing.
*
* Compile with:
* gcc -Wall -o scanftest scanftest.c
*
* Run with:
* ./scanftest < data
* or
* ./scanftest < data | diff data -
*
* The output should coincide with the input, but it doesn't.
*/
int
main()
{
int n;
char name[3];
int hw[17];
int i;
n = 0;
for (;;) {
double h[17];
double junk;
i = scanf("%c%c%c "
"%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf "
"%lf %lf %lf %lf\n",
&name[0], &name[1], &name[2],
&h[0], &h[1], &h[2], &h[3], &h[4], &h[5], &h[6], &h[7], &h[8],
&h[9], &h[10], &h[11], &h[12], &h[13], &h[14], &h[15], &h[16],
&junk);
if (i == EOF) break;
if (i != 20) {
fprintf(stderr, "At line %d, got %d values instead of 20.\n",
n + 1, i);
return 1;
}
for (i = 0; i < 17; ++i)
hw[i] = h[i];
printf("%c%c%c", name[0], name[1], name[2]);
for (i = 0; i < 16; ++i)
printf(" %2d", hw[i]);
printf("%2d\n", hw[16]);
++n;
}
return 0;
}
Abc 0 1 2 3 4 5 6 7 8 9 10 11 12 13 23 34 0
Bcd 1 2 3 4 5 6 7 8 9 10 11 12 13 14 24 35 0
Cde 2 3 4 5 6 7 8 9 10 11 12 13 14 15 25 36 0
Def 3 4 5 6 7 8 9 10 11 12 13 14 15 16 26 37 0
Efg 4 5 6 7 8 9 10 11 12 13 14 15 16 17 27 38 0
Fgh 5 6 7 8 9 10 11 12 13 14 15 16 17 18 28 39 0
Ghi 6 7 8 9 10 11 12 13 14 15 16 17 18 19 29 40 0
Hij 7 8 9 10 11 12 13 14 15 16 17 18 19 20 30 41 0
Ijk 8 9 10 11 12 13 14 15 16 17 18 19 20 21 31 42 0
Jkl 9 10 11 12 13 14 15 16 17 18 19 20 21 22 32 43 0
Klm 10 11 12 13 14 15 16 17 18 19 20 21 22 23 33 44 0
Lmn 11 12 13 14 15 16 17 18 19 20 21 22 23 24 34 45 0
Mno 12 13 14 15 16 17 18 19 20 21 22 23 24 25 35 46 0
Nop 13 14 15 16 17 18 19 20 21 22 23 24 25 26 36 47 0
Opq 14 15 16 17 18 19 20 21 22 23 24 25 26 27 37 48 0
Pqr 15 16 17 18 19 20 21 22 23 24 25 26 27 28 38 49 0
Reply to: