[ros-bugs] [Bug 2803] New: text FILE ftell filebuf ungetc read cnt internal incompatibility

ReactOS.Bugzilla at www.reactos.org ReactOS.Bugzilla at www.reactos.org
Fri Nov 9 00:21:06 CET 2007


http://www.reactos.org/bugzilla/show_bug.cgi?id=2803

           Summary: text FILE ftell filebuf ungetc read cnt internal
                    incompatibility
           Product: ReactOS
           Version: TRUNK
          Platform: QEmu
        OS/Version: ReactOS
            Status: NEW
          Severity: normal
          Priority: P3
         Component: Win32
        AssignedTo: ros-bugs at reactos.org
        ReportedBy: jeanmichel.123 at free.Fr
         QAContact: ros-bugs at reactos.org


Python cannot read text file (using getc and ungetc) due to reactos MSVCRT.

python:
1/ open a text file
2/ getc a character (broking FILE internal compatibility with ftell)
3/ ungetc this character
4/ read a second character (and not the good one due to 2 side effect)

In point2,
lib/sdk/crt/stdio/getc.c
To getc the first character, getc.c calls filebuf

lib/sdk/crt/stdio/filbuf.c
To get its buffer, filebuf call read for 4096 bytes.

lib/sdk/crt/io/read.c
Because there are CRLF issues, _read return 3972.

lib/sdk/crt/stdio/filbuf.c
filbuf set FILE->cnt, according to _read return: 3972

lib/sdk/crt/stdio/ftell.c
ftell return _lseek(_fileno(f), 0L, SEEK_CUR) - f->_cnt
ie 4096 - 3972 = 124

This makes the second getc read bytes 123 instead of byte 0.




Trace here after details point 2.

(MSVCRT:lib/sdk/crt/stdio/ftell.c:16) *FILE:ftell  :
(MSVCRT:lib/sdk/crt/io/lseek.c:10) *FILE:_lseek :
(MSVCRT:lib/sdk/crt/io/lseek.c:11) *FILE:_lseek :3 0 1
(MSVCRT:lib/sdk/crt/stdio/ftell.c:38) *FILE:ftell  : 0  0
(MSVCRT:lib/sdk/crt/stdio/ftell.c:46) *FILE:ftell  : --> 0
(MSVCRT:lib/sdk/crt/stdio/filbuf.c:21) *FILE:filbuf      :
(MSVCRT:lib/sdk/crt/stdio/filbuf.c:22) *FILE:filbuf      : 1D251930 :
(MSVCRT:lib/sdk/crt/stdio/filbuf.c:25) *FILE:filbuf      : 1D251930 : flag: 1
base:00000000 ptr:00000000 cnt:0
(MSVCRT:lib/sdk/crt/stdio/filbuf.c:106) *FILE:filbuf fin     :
(MSVCRT:lib/sdk/crt/stdio/filbuf.c:107) *FILE:filbuf fin     : 1D251930 :
(MSVCRT:lib/sdk/crt/stdio/filbuf.c:110) *FILE:filbuf fin     : 1D251930 : flag:
20009 base:1D3483C0 ptr:1D3483C0 cnt:3972
(MSVCRT:lib/sdk/crt/stdio/rewind.c:11) *FILE:rewind   :
(MSVCRT:lib/sdk/crt/io/lseek.c:10) *FILE:_lseek :
(MSVCRT:lib/sdk/crt/io/lseek.c:11) *FILE:_lseek :3 0 0
(MSVCRT:lib/sdk/crt/stdio/getc.c:45) *FILE:getc      :
(MSVCRT:lib/sdk/crt/stdio/getc.c:46) *FILE:getc      : 1D251930 :-1: '�'
(MSVCRT:lib/sdk/crt/stdio/ftell.c:16) *FILE:ftell  :
(MSVCRT:lib/sdk/crt/io/lseek.c:10) *FILE:_lseek :
(MSVCRT:lib/sdk/crt/io/lseek.c:11) *FILE:_lseek :3 0 1
(MSVCRT:lib/sdk/crt/stdio/ftell.c:38) *FILE:ftell  : 0  0
(MSVCRT:lib/sdk/crt/stdio/ftell.c:46) *FILE:ftell  : --> 0
(MSVCRT:lib/sdk/crt/stdio/getc.c:48) *FILE:getc      : 1D251930 : offset: 0
(MSVCRT:lib/sdk/crt/stdio/filbuf.c:21) *FILE:filbuf      :
(MSVCRT:lib/sdk/crt/stdio/filbuf.c:22) *FILE:filbuf      : 1D251930 :
(MSVCRT:lib/sdk/crt/stdio/filbuf.c:25) *FILE:filbuf      : 1D251930 : flag: 9
base:1D3483C0 ptr:1D3483C0 cnt:0
(MSVCRT:lib/sdk/crt/stdio/filbuf.c:106) *FILE:filbuf fin     :
(MSVCRT:lib/sdk/crt/stdio/filbuf.c:107) *FILE:filbuf fin     : 1D251930 :
(MSVCRT:lib/sdk/crt/stdio/filbuf.c:110) *FILE:filbuf fin     : 1D251930 : flag:
20009 base:1D3483C0 ptr:1D3483C0 cnt:3972
(MSVCRT:lib/sdk/crt/stdio/getc.c:69) *FILE:getc      :
(MSVCRT:lib/sdk/crt/stdio/getc.c:70) *FILE:getc      : 1D251930 :35: '#'
(MSVCRT:lib/sdk/crt/stdio/ftell.c:16) *FILE:ftell  :
(MSVCRT:lib/sdk/crt/io/lseek.c:10) *FILE:_lseek :
(MSVCRT:lib/sdk/crt/io/lseek.c:11) *FILE:_lseek :3 0 1
(MSVCRT:lib/sdk/crt/stdio/ftell.c:38) *FILE:ftell  : 4096  -3972
(MSVCRT:lib/sdk/crt/stdio/ftell.c:46) *FILE:ftell  : --> 124
(MSVCRT:lib/sdk/crt/stdio/getc.c:72) *FILE:getc      : 1D251930 : offset: 124


-- 
Configure bugmail: http://www.reactos.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the Ros-bugs mailing list