Skip to content

Commit 77c73c3

Browse files
Fix an additional warning that shows up with the latest clang.
1 parent a8ace10 commit 77c73c3

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

test/basics/read.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
#include <unistd.h>
77

88
char const cfilename[] = "test_qthread_read.XXXXXXXXXXXXX";
9+
#define BUFFER_SIZE 32u // strlen(cfilename) + 1
910

1011
static aligned_t reader(void *arg) {
1112
int ret;
12-
char buf[strlen(cfilename) + 1];
13+
char buf[BUFFER_SIZE];
1314

14-
memset(buf, 0, strlen(cfilename) + 1);
15+
memset(buf, 0, BUFFER_SIZE);
1516
iprintf("in reader function\n");
1617
ret = read((int)(intptr_t)arg, buf, 5);
1718
iprintf("read '%s'\n", buf);
@@ -29,12 +30,12 @@ static aligned_t reader(void *arg) {
2930
int main(int argc, char *argv[]) {
3031
aligned_t t;
3132
int fd;
32-
char filename[strlen(cfilename) + 1];
33+
char filename[BUFFER_SIZE];
3334
ssize_t ret;
3435

3536
CHECK_VERBOSE();
3637

37-
snprintf(filename, strlen(cfilename) + 1, "%s", cfilename);
38+
snprintf(filename, BUFFER_SIZE, "%s", cfilename);
3839
iprintf("filename = '%s'\n", filename);
3940

4041
/* First, set up a temporary file */
@@ -44,8 +45,8 @@ int main(int argc, char *argv[]) {
4445
if (fd < 0) { perror("mkstemp failed"); }
4546
assert(fd >= 0);
4647

47-
ret = write(fd, cfilename, strlen(cfilename));
48-
assert(ret == strlen(cfilename));
48+
ret = write(fd, cfilename, BUFFER_SIZE - 1u);
49+
assert(ret == BUFFER_SIZE - 1u);
4950

5051
ret = (ssize_t)lseek(fd, 0, SEEK_SET);
5152
assert(ret == 0);

0 commit comments

Comments
 (0)