Skip to content

Commit

Permalink
examples/pipe/interlock_test.c: fix the uses of uninitialized variables
Browse files Browse the repository at this point in the history
found by clang warnings.
  • Loading branch information
yamt authored and xiaoxiang781216 committed Jan 7, 2025
1 parent b73adbe commit da615bf
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions examples/pipe/interlock_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -208,15 +208,15 @@ 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)
{
fprintf(stderr, \
"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");
Expand All @@ -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");
Expand Down Expand Up @@ -290,15 +292,15 @@ 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)
{
fprintf(stderr, \
"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");
Expand All @@ -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");
Expand All @@ -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);
Expand All @@ -351,6 +349,11 @@ int interlock_test(void)

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)
{
Expand Down

0 comments on commit da615bf

Please sign in to comment.