Skip to content

Commit b63c4a6

Browse files
committed
Fix stderr redirection
You cannot modify dereferenced FILE, this is UB. FILE may also be opaque type so this code may not compile (and in fact it doesn't compile on DragonFlyBSD). freopen is quite enough to do the thing.
1 parent 15fb9b6 commit b63c4a6

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

src/posix/OSPosix.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,10 @@ void RedirectStdio()
4040
FILE *f;
4141

4242
f = freopen(output_path.c_str(), "w", stderr);
43-
if (!f)
44-
f = fopen(output_path.c_str(), "w");
4543
if (!f)
4644
Output("ERROR: Couldn't redirect output to '%s': %s\n", output_path.c_str(), strerror(errno));
47-
else {
45+
else
4846
setvbuf(f, 0, _IOLBF, BUFSIZ);
49-
*stderr = *f;
50-
}
5147
}
5248

5349
void EnableFPE()

0 commit comments

Comments
 (0)