Skip to content

Commit 0fdaa88

Browse files
committed
fix major bug with unflushed stdio
1 parent 4f5d871 commit 0fdaa88

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

dcc_check_output.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
static unsigned char *expected_stdout;
2+
13
#if !__CHECK_OUTPUT__ || !__I_AM_SANITIZER1__
24

35
static int init_check_output(void) {
@@ -11,11 +13,14 @@ static void __dcc_check_close(int fd) {
1113
}
1214

1315
static void __dcc_check_output_exit(void) {
14-
debug_printf(3, "__dcc_cleanup_before_exit\n");
15-
fflush(stdout);
16+
debug_printf(3, "__dcc_check_output_exit\n");
17+
if (expected_stdout) {
18+
fflush(stdout);
19+
}
1620
}
1721

1822
static void disable_check_output(void) {
23+
expected_stdout = NULL;
1924
}
2025

2126
#else
@@ -27,8 +32,6 @@ static void disable_check_output(void) {
2732
//lins longer than this will produce an error if output checking enabled
2833
#define ACTUAL_LINE_MAX 65536
2934

30-
static unsigned char *expected_stdout;
31-
3235
static int ignore_case;
3336
static int ignore_empty_lines;
3437
static int ignore_trailing_white_space;
@@ -118,7 +121,7 @@ static void __dcc_check_close(int fd) {
118121
}
119122

120123
static void __dcc_check_output_exit(void) {
121-
debug_printf(3, "__dcc_cleanup_before_exit\n");
124+
debug_printf(3, "__dcc_check_output_exit\n");
122125
if (expected_stdout) {
123126
fflush(stdout);
124127
__dcc_check_all_output_seen_at_exit();

dcc_dual_sanitizers.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,6 @@ static void disconnect_sanitizers(void) {
141141
if (synchronization_terminated) {
142142
return;
143143
}
144-
// sanitizer2 sends SIGUSR1 if its printing an error
145-
signal(SIGUSR1, SIG_IGN);
146-
signal(SIGPIPE, SIG_IGN);
147144
#if __I_AM_SANITIZER1__
148145
close(to_sanitizer2_pipe[1]);
149146
close(from_sanitizer2_pipe[0]);
@@ -164,6 +161,9 @@ static void wait_for_sanitizer2_to_terminate(void) {
164161
set_signals_default();
165162
debug_printf(3, "waiting\n");
166163
if (!sanitizer2_killed) {
164+
// sanitizer2 sends SIGUSR1 if its printing an error
165+
signal(SIGUSR1, SIG_IGN);
166+
signal(SIGPIPE, SIG_IGN);
167167
pid_t pid = wait(NULL);
168168
debug_printf(3, "wait returned %d\n", pid);
169169
if (pid != sanitizer2_pid) {

dcc_util.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ static void set_signals_default(void) {
186186
}
187187

188188
static void __dcc_signal_handler(int signum) {
189+
debug_printf(2, "received signal %d\n", signum);
189190
set_signals_default();
190191
#if __N_SANITIZERS__ > 1
191192
#if __I_AM_SANITIZER1__
@@ -196,7 +197,6 @@ static void __dcc_signal_handler(int signum) {
196197
__dcc_error_exit();
197198
}
198199
} else if (signum == SIGUSR1) {
199-
debug_printf(2, "received SIGUSR\n");
200200
__dcc_error_exit();
201201
}
202202
#else

docs/eof_byte.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Accidentally printing the special **EOF** value returned by the functions _getchar_, _getc_ and _fgetc_.
1+
Accidentally printing the special **EOF** value returned by the functions _getchar_, _getc_ and _fgetc_ is common bug.
22

33
For example, this program prints the **EOF** value before the loop exits:
44

0 commit comments

Comments
 (0)