This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libc/4745] New: Wrong results from scanf with errno set to EINTR


Calling scanf with errno set to EINTR produces wrong results with glibc 2.6


Here is a test program.

#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);
}

How to reproduce 
gcc test.c -o test

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 version 2.2.4 scanf assigns n the correct value of 4.

There is patch ( I dont know if this is the right fix) and problem reported against 2.3.2 below

http://lists.gnu.org/archive/html/bug-glibc/2003-11/msg00067.html

-- 
           Summary: Wrong results from scanf with errno set to EINTR
           Product: glibc
           Version: 2.4
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
        AssignedTo: drepper at redhat dot com
        ReportedBy: raj dot khem at gmail dot com
                CC: glibc-bugs at sources dot redhat dot com
 GCC build triplet: i486-linux-gnu
  GCC host triplet: i486-linux-gnu
GCC target triplet: i486-linux-gnu


http://sourceware.org/bugzilla/show_bug.cgi?id=4745

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]