From da615bf5a6eafca8ab3af101c8f1d139d2257d4a Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Tue, 7 Jan 2025 20:25:19 +0900 Subject: [PATCH] examples/pipe/interlock_test.c: fix the uses of uninitialized variables found by clang warnings. --- examples/pipe/interlock_test.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/examples/pipe/interlock_test.c b/examples/pipe/interlock_test.c index 7d614e78a..6be9b6ec4 100644 --- a/examples/pipe/interlock_test.c +++ b/examples/pipe/interlock_test.c @@ -155,7 +155,7 @@ int interlock_test(void) void *value; char data[16]; ssize_t nbytes; - int fd; + int fd = -1; int ret; /* Create a FIFO */ @@ -208,7 +208,7 @@ int interlock_test(void) fprintf(stderr, \ "interlock_test: read failed, errno=%d\n", errno); ret = 4; - goto errout_with_file; + goto errout_with_null_writer_thread; } else if (ret != 0) { @@ -216,7 +216,7 @@ int interlock_test(void) "interlock_test: Read %ld bytes of data -- aborting: %d\n", (long)nbytes, errno); ret = 5; - goto errout_with_file; + goto errout_with_null_writer_thread; } printf("interlock_test: read returned\n"); @@ -229,6 +229,8 @@ int interlock_test(void) fprintf(stderr, "interlock_test: close failed: %d\n", errno); } + fd = -1; + /* Wait for null_writer thread to complete */ printf("interlock_test: Waiting for null_writer thread\n"); @@ -290,7 +292,7 @@ int interlock_test(void) fprintf(stderr, \ "interlock_test: write failed, errno=%d\n", errno); ret = 10; - goto errout_with_file; + goto errout_with_null_reader_thread; } else if (ret != 0) { @@ -298,7 +300,7 @@ int interlock_test(void) "interlock_test: Wrote %ld bytes of data -- aborting: %d\n", (long)nbytes, errno); ret = 11; - goto errout_with_file; + goto errout_with_null_reader_thread; } printf("interlock_test: write returned\n"); @@ -311,6 +313,8 @@ int interlock_test(void) fprintf(stderr, "interlock_test: close failed: %d\n", errno); } + fd = -1; + /* Wait for null_reader thread to complete */ printf("interlock_test: Waiting for null_reader thread\n"); @@ -335,12 +339,6 @@ int interlock_test(void) ret = 0; goto errout_with_fifo; -errout_with_file: - if (close(fd) != 0) - { - fprintf(stderr, "interlock_test: close failed: %d\n", errno); - } - errout_with_null_reader_thread: pthread_detach(readerid); pthread_cancel(readerid); @@ -351,6 +349,11 @@ errout_with_null_writer_thread: errout_with_fifo: + if (fd != -1 && close(fd) != 0) + { + fprintf(stderr, "interlock_test: close failed: %d\n", errno); + } + ret = remove(FIFO_PATH2); if (ret != 0) {