Skip to content

Commit 23376c9

Browse files
authored
Merge pull request #124 from yury/fix-ios_dup2
Check FILE* is not NULL before calling fileno function
2 parents cf57413 + eb1b3a0 commit 23376c9

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

ios_system.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1696,9 +1696,9 @@ int ios_dup2(int fd1, int fd2)
16961696
case 2: child_stderr = stream1; return fd2;
16971697
}
16981698
}
1699-
if ((fd2 == 0) || (fd2 == fileno(thread_stdin))) { child_stdin = fdopen(fd1, "rb"); }
1700-
else if ((fd2 == 1) || (fd2 == fileno(thread_stdout))) { child_stdout = fdopen(fd1, "wb"); }
1701-
else if ((fd2 == 2) || (fd2 == fileno(thread_stderr))) {
1699+
if ((fd2 == 0) || (thread_stdin != NULL && fd2 == fileno(thread_stdin))) { child_stdin = fdopen(fd1, "rb"); }
1700+
else if ((fd2 == 1) || (thread_stdout != NULL && fd2 == fileno(thread_stdout))) { child_stdout = fdopen(fd1, "wb"); }
1701+
else if ((fd2 == 2) || (thread_stderr != NULL && fd2 == fileno(thread_stderr))) {
17021702
if ((child_stdout != NULL) && (fileno(child_stdout) == fd1)) child_stderr = child_stdout;
17031703
else child_stderr = fdopen(fd1, "wb"); }
17041704
else if (fd1 != fd2) {

0 commit comments

Comments
 (0)