Skip to content

Commit

Permalink
fix major bug with unflushed stdio
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-taylor committed Jul 26, 2019
1 parent 4f5d871 commit 0fdaa88
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
13 changes: 8 additions & 5 deletions dcc_check_output.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
static unsigned char *expected_stdout;

#if !__CHECK_OUTPUT__ || !__I_AM_SANITIZER1__

static int init_check_output(void) {
Expand All @@ -11,11 +13,14 @@ static void __dcc_check_close(int fd) {
}

static void __dcc_check_output_exit(void) {
debug_printf(3, "__dcc_cleanup_before_exit\n");
fflush(stdout);
debug_printf(3, "__dcc_check_output_exit\n");
if (expected_stdout) {
fflush(stdout);
}
}

static void disable_check_output(void) {
expected_stdout = NULL;
}

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

static unsigned char *expected_stdout;

static int ignore_case;
static int ignore_empty_lines;
static int ignore_trailing_white_space;
Expand Down Expand Up @@ -118,7 +121,7 @@ static void __dcc_check_close(int fd) {
}

static void __dcc_check_output_exit(void) {
debug_printf(3, "__dcc_cleanup_before_exit\n");
debug_printf(3, "__dcc_check_output_exit\n");
if (expected_stdout) {
fflush(stdout);
__dcc_check_all_output_seen_at_exit();
Expand Down
6 changes: 3 additions & 3 deletions dcc_dual_sanitizers.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,6 @@ static void disconnect_sanitizers(void) {
if (synchronization_terminated) {
return;
}
// sanitizer2 sends SIGUSR1 if its printing an error
signal(SIGUSR1, SIG_IGN);
signal(SIGPIPE, SIG_IGN);
#if __I_AM_SANITIZER1__
close(to_sanitizer2_pipe[1]);
close(from_sanitizer2_pipe[0]);
Expand All @@ -164,6 +161,9 @@ static void wait_for_sanitizer2_to_terminate(void) {
set_signals_default();
debug_printf(3, "waiting\n");
if (!sanitizer2_killed) {
// sanitizer2 sends SIGUSR1 if its printing an error
signal(SIGUSR1, SIG_IGN);
signal(SIGPIPE, SIG_IGN);
pid_t pid = wait(NULL);
debug_printf(3, "wait returned %d\n", pid);
if (pid != sanitizer2_pid) {
Expand Down
2 changes: 1 addition & 1 deletion dcc_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ static void set_signals_default(void) {
}

static void __dcc_signal_handler(int signum) {
debug_printf(2, "received signal %d\n", signum);
set_signals_default();
#if __N_SANITIZERS__ > 1
#if __I_AM_SANITIZER1__
Expand All @@ -196,7 +197,6 @@ static void __dcc_signal_handler(int signum) {
__dcc_error_exit();
}
} else if (signum == SIGUSR1) {
debug_printf(2, "received SIGUSR\n");
__dcc_error_exit();
}
#else
Expand Down
2 changes: 1 addition & 1 deletion docs/eof_byte.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Accidentally printing the special **EOF** value returned by the functions _getchar_, _getc_ and _fgetc_.
Accidentally printing the special **EOF** value returned by the functions _getchar_, _getc_ and _fgetc_ is common bug.

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

Expand Down

0 comments on commit 0fdaa88

Please sign in to comment.