From: Michal H. <ms...@gm...> - 2009-08-10 09:02:31
|
On Mon, Aug 10, 2009 at 10:46:47AM +0200, Michal Hocko wrote: > On Sun, Aug 09, 2009 at 10:15:17PM +0000, Jozef Misutka wrote: [...] > I would consider this as Windows specific ill-behavior. Handling > end-line in text mode differently than in binary mode sounds little bit > crazy to me. > [...] > > And one last thing. If fread translates end-lines on the background and > it returns correct numbers of read elements then we should be safe, > shouldn't we? > The code is prepared for \r\n vs \n and we are getting data from already > read buffer. > > Stream::getLine > -> for() > getChar() > if (EOF || \n) > break > if (\r) && lookChar == \n > getChar(); > > FileStream::getChar() > return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr++ & 0xff); > > FileStream::lookChar is basically same excpet it doesnt update bufPtr. > > FileStream::fillBuffer() > { > [...] > n = fread(buf, 1, n, f); > bufEnd = buf + n; > [...] > } > > How this can be off-by-one? Ahh, I've got it. This is about fread return value: " fread returns the number of full items actually read... " This is expected but: " If the given stream is opened in text mode, carriage return?linefeed pairs are replaced with single linefeed characters. The replacement has no effect on the file pointer or the return value. " That means that you don't have any idea what has been filled into the buffer unless you prefill it with 0 before you call fread. Crazy! fread is really useless in Windows for text files. > I am little bit confused about that. Could you check it? > > Btw. I have already prepared patch but I would like to be sure I > understand where is the problem before I commit it. I will add this into the log message and commit it right away. > > > > > http://pdfedit.petricek.net/bt/view.php?id=324 > > > > > > /jozo > > -- > Michal Hocko > > ------------------------------------------------------------------------------ > Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day > trial. Simplify your report design, integration and deployment - and focus on > what you do best, core application coding. Discover what's new with > Crystal Reports now. http://p.sf.net/sfu/bobj-july > _______________________________________________ > Pdfedit-devel mailing list > Pdf...@li... > https://lists.sourceforge.net/lists/listinfo/pdfedit-devel -- Michal Hocko |