fix undefined call order in fclose, possible lost output depending on compiler
authorRich Felker <dalias@aerifal.cx>
Mon, 2 May 2011 02:59:14 +0000 (22:59 -0400)
committerRich Felker <dalias@aerifal.cx>
Mon, 2 May 2011 02:59:14 +0000 (22:59 -0400)
pcc turned up this bug by calling f->close(f) before fflush(f),
resulting in lost output and error on flush.

src/stdio/fclose.c

index 26bc37e..9481470 100644 (file)
@@ -13,7 +13,7 @@ int fclose(FILE *f)
                OFLUNLOCK();
        }
 
-       r = fflush(f) | f->close(f);
+       r = -(fflush(f) || f->close(f));
 
        if (!perm) free(f);