Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions test/unistd/test_unistd_write_broken_link.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
Expand All @@ -16,15 +17,19 @@ int main() {
int target_fd = open("link_target", O_RDONLY);
printf("target_fd: %d, errno: %d %s\n", target_fd, errno, strerror(errno));
char buf[10];
read(target_fd, buf, 10);
memset(buf, 0, 10);
size_t r = read(target_fd, buf, 10);
assert(r == 3);
printf("buf: '%s'\n", buf);
close(target_fd);
}
{
int target_fd = open("link_source", O_RDONLY);
printf("target_fd: %d, errno: %d %s\n", target_fd, errno, strerror(errno));
char buf[10];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative here I suppose would be intialize buf on the stack with char buf[10] = { '\0' };

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I could go either way on that, do you have a preference?

read(target_fd, buf, 10);
memset(buf, 0, 10);
size_t r = read(target_fd, buf, 10);
assert(r == 3);
printf("buf: '%s'\n", buf);
close(target_fd);
}
Expand Down
Loading