stdio buffering leaves stderr.txt truncated in a crash

Found a bug in R'n'D? Report it here!

Moderators: Flumminator, Zomis

Post Reply
filbo
Posts: 647
Joined: Fri Jun 20, 2014 10:06 am

stdio buffering leaves stderr.txt truncated in a crash

Post by filbo »

setbuf() should be compatible with all RnD port targets.

Code: Select all

--- src/libgame/misc.c.orig	2013-11-22 11:04:23.000000000 -0800
+++ src/libgame/misc.c	2014-07-12 22:22:19.000000000 -0700
@@ -3107,6 +3107,11 @@
   if ((program.error_file = fopen(program.error_filename, MODE_WRITE)) == NULL)
     fprintf_newline(stderr, "ERROR: cannot open file '%s' for writing!",
 		    program.error_filename);
+  else
+  {
+    /* stderr should be unbuffered so it is not truncated in a crash */
+    setbuf(program.error_file, NULL);
+  }
 }
 
 void closeErrorFile()
User avatar
Holger
Site Admin
Posts: 4073
Joined: Fri Jun 18, 2004 4:13 pm
Location: Germany
Contact:

Re: stdio buffering leaves stderr.txt truncated in a crash

Post by Holger »

This fix is already incorporated into the current development version of R'n'D, available from the Git repository!

Thanks a lot for this addition! :-)
Post Reply