Menu

#525 Extra CR printed on dos/win32

open
nobody
rtlib (39)
2012-10-09
2011-01-08
dkl
No

The rtlib uses \r\n when printing newlines to stdout, but it should use just \n. The C runtime replaces any \n by \r\n because stdout is opened in text mode, so we end up printing \r\r\n.

Main problem observed with DOS FB:
FreeBASIC/src/rtlib/dos/libfb_io_printbuff.c uses fwrite(stdout) when stdout is redirected, and it turns CRLF into CRCRLF.
--- 1.bas ---
print "a"
print "b";
--- run ---
$ fbc 1.bas
$ 1 > 1.txt
--- 1.txt ---
a<cr>
<cr><lf>
b
--- EOF ---</lf></cr></cr>

It also happens with the rtlib's runtime error messages, which are snprintf()'ed into a buffer and then fprintf()'ed to stderr, observed on DOS and also Windows.
--- 2.bas ---
dim as integer ptr p = 0
*p = 5
--- run ---
$ fbc 2.bas -exx
$ 2 > 2.txt 2>&1
--- 2.txt ---
<cr>
<cr><lf>
Aborting due to runtime error 7 (null pointer access) at line 2 of 2.bas::()<cr>
<cr><lf>
<cr>
<cr><lf>
--- EOF ---</lf></cr></cr></lf></cr></cr></lf></cr></cr>

http://www.freebasic.net/forum/viewtopic.php?t=17124
http://www.freebasic.net/forum/viewtopic.php?t=5672

Discussion

  • dkl

    dkl - 2011-08-06

    As found in bug 3369993 this also happens with OPEN CONS and stdout being redirected to a file on Windows:

    open cons for output as #1
    print #1, ""
    close #1

     

Log in to post a comment.

MongoDB Logo MongoDB