[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Calling scanf with errno set to EINTR produces wrong results in glibc-2.
From: |
Knut . Beneke |
Subject: |
Calling scanf with errno set to EINTR produces wrong results in glibc-2.3.2 |
Date: |
Mon, 17 Nov 2003 09:14:31 +0100 |
Description:
============
Calling scanf with errno set to EINTR produces wrong results in glibc
2.3.2.
Source of test program:
=======================
--- begin ---
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <unistd.h>
#include <time.h>
#include <assert.h>
#include <errno.h>
/*********************************************************************/
int main(int argc, char* argv[])
{
printf("setting errno to EINTR\n");
errno = EINTR;
printf("checking sscanf\n");
{
char str[] = "7-11";
int i, j, n;
i = j = n = 0;
sscanf(str, " %i - %i %n", &i, &j, &n);
printf("found %i-%i (length=%i)\n", i, j, n);
assert(i==7);
assert(j==11);
assert(n==4);
}
return(0);
}
---end ---
How-To-Reproduce:
=================
Compile glibc-2.3.2
Compile test.c with:
gcc -c test.c -I <glibc-2.3.2-install-path>/include
gcc -o test -nodefaultlibs -static test.o
<glibc-2.3.2-install-path>/lib/libc.a
usr/lib/gcc-lib/i586-mandrake-linux-gnu/3.2/libgcc.a
If glibc-2.3.2 is installed use:
gcc -o test test.c
Running ./test will now cause an assertion (assert(n==4) at the end of
test.c).
The output looks like this:
---begin ---
setting errno to EINTR
checking sscanf
found 7-11 (length=0)
test: test.c:27: main: Assertion `n==4' failed.
Aborted (core dumped)
---end ---
In older glibc versions (tested: 2.2.4) scanf assigns n the correct value
of 4.
Patch:
======
---begin ---
--- glibc-2.3.2/stdio-common/vfscanf.c.original Mon Nov 17 08:53:57 2003
+++ glibc-2.3.2/stdio-common/vfscanf.c Mon Nov 17 08:54:20 2003
@@ -340,6 +340,9 @@
wp[wpsize++] = (Ch); \
} \
while (0)
+
+ /* Reset errno */
+ errno = 0;
#ifdef __va_copy
__va_copy (arg, argptr);
---end ---
Best regards,
Knut Beneke
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Calling scanf with errno set to EINTR produces wrong results in glibc-2.3.2,
Knut . Beneke <=