Module: wine Branch: master Commit: b4c1c67ea46ec49eb0a89ab039749d56986fec82 URL: http://source.winehq.org/git/wine.git/?a=commit;h=b4c1c67ea46ec49eb0a89ab039...
Author: Duane Clark fpga@pacbell.net Date: Thu Oct 26 16:28:11 2006 -0700
msvcrt: Fix fread on large buffers in ascii mode.
---
dlls/msvcrt/file.c | 3 ++- dlls/msvcrt/tests/file.c | 30 ++++++++++++++++++++---------- 2 files changed, 22 insertions(+), 11 deletions(-)
diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c index 146e0f3..1956a7c 100644 --- a/dlls/msvcrt/file.c +++ b/dlls/msvcrt/file.c @@ -2550,8 +2550,9 @@ MSVCRT_size_t CDECL MSVCRT_fread(void *p } pread += i; rcnt -= i; + ptr = (char *)ptr+i; /* expose feof condition in the flags - * MFC tests file->_flag for feof, and doesn't not call feof()) + * MFC tests file->_flag for feof, and doesn't call feof()) */ if ( MSVCRT_fdesc[file->_file].wxflag & WX_ATEOF) file->_flag |= MSVCRT__IOEOF; diff --git a/dlls/msvcrt/tests/file.c b/dlls/msvcrt/tests/file.c index d269765..bd4bd5f 100644 --- a/dlls/msvcrt/tests/file.c +++ b/dlls/msvcrt/tests/file.c @@ -139,20 +139,20 @@ static void test_readmode( BOOL ascii_mo static const char outbuffer[] = "0,1,2,3,4,5,6,7,8,9\r\n\r\nA,B,C,D,E\r\nX,Y,Z"; static const char padbuffer[] = "ghjghjghjghj"; static const char nlbuffer[] = "\r\n"; - char buffer[MSVCRT_BUFSIZ+256]; + char buffer[2*MSVCRT_BUFSIZ+256], *optr; int fd; FILE *file; - int i, j, fp, ao, *ip, pl; + int i, j, m, fp, ao, *ip, pl; long l;
fd = open ("fdopen.tst", O_WRONLY | O_CREAT | O_BINARY, _S_IREAD |_S_IWRITE); /* an internal buffer of MSVCRT_BUFSIZ is maintained, so make a file big * enough to test operations that cross the buffer boundary */ - j = (MSVCRT_BUFSIZ-4)/strlen(padbuffer); + j = (2*MSVCRT_BUFSIZ-4)/strlen(padbuffer); for (i=0; i<j; i++) write (fd, padbuffer, strlen(padbuffer)); - j = (MSVCRT_BUFSIZ-4)%strlen(padbuffer); + j = (2*MSVCRT_BUFSIZ-4)%strlen(padbuffer); for (i=0; i<j; i++) write (fd, &padbuffer[i], 1); write (fd, nlbuffer, strlen(nlbuffer)); @@ -173,9 +173,9 @@ static void test_readmode( BOOL ascii_mo
/* first is a test of fgets, ftell, fseek */ ok(ftell(file) == 0,"Did not start at beginning of file in %s\n", IOMODE); - ok(fgets(buffer,MSVCRT_BUFSIZ+256,file) !=0,"padding line fgets failed unexpected in %s\n", IOMODE); + ok(fgets(buffer,2*MSVCRT_BUFSIZ+256,file) !=0,"padding line fgets failed unexpected in %s\n", IOMODE); l = ftell(file); - pl = MSVCRT_BUFSIZ-2; + pl = 2*MSVCRT_BUFSIZ-2; ok(l == pl,"padding line ftell got %ld should be %d in %s\n", l, pl, IOMODE); ok(lstrlenA(buffer) == pl+ao,"padding line fgets got size %d should be %d in %s\n", lstrlenA(buffer), pl+ao, IOMODE); @@ -209,10 +209,20 @@ static void test_readmode( BOOL ascii_mo ok(ftell(file) == 0,"Did not start at beginning of file in %s\n", IOMODE); ok(fgets(buffer,MSVCRT_BUFSIZ-6,file) !=0,"padding line fgets failed unexpected in %s\n", IOMODE); j=strlen(outbuffer); - i=fread(buffer,1,256,file); - ok(i==j+6+ao*4,"fread failed, expected %d got %d in %s\n", j+6+ao*4, i, IOMODE); + i=fread(buffer,1,MSVCRT_BUFSIZ+strlen(outbuffer),file); + ok(i==MSVCRT_BUFSIZ+j,"fread failed, expected %d got %d in %s\n", MSVCRT_BUFSIZ+j, i, IOMODE); l = ftell(file); - ok(l == pl+j+1,"ftell after fread got %ld should be %d in %s\n", l, pl+j+1, IOMODE); + ok(l == pl+j-(ao*4)-5,"ftell after fread got %ld should be %d in %s\n", l, pl+j-(ao*4)-5, IOMODE); + for (m=0; m<3; m++) + ok(buffer[m]==padbuffer[m+(MSVCRT_BUFSIZ-4)%strlen(padbuffer)],"expected %c got %c\n", padbuffer[m], buffer[m]); + m+=MSVCRT_BUFSIZ+2+ao; + optr = (char *)outbuffer; + for (; m<i; m++) { + ok(buffer[m]==*optr,"char %d expected %c got %c in %s\n", m, *optr, buffer[m], IOMODE); + optr++; + if (ao && (*optr == '\r')) + optr++; + } /* fread should return the requested number of bytes if available */ rewind(file); ok(ftell(file) == 0,"Did not start at beginning of file in %s\n", IOMODE); @@ -235,7 +245,7 @@ static void test_readmode( BOOL ascii_mo /* test some additional functions */ rewind(file); ok(ftell(file) == 0,"Did not start at beginning of file in %s\n", IOMODE); - ok(fgets(buffer,MSVCRT_BUFSIZ+256,file) !=0,"padding line fgets failed unexpected in %s\n", IOMODE); + ok(fgets(buffer,2*MSVCRT_BUFSIZ+256,file) !=0,"padding line fgets failed unexpected in %s\n", IOMODE); i = _getw(file); ip = (int *)outbuffer; ok(i == *ip,"_getw failed, expected %08x got %08x in %s\n", *ip, i, IOMODE);