Skip to content

Commit

Permalink
tests: fixed following compilation warnings:
Browse files Browse the repository at this point in the history
```
path_utils/path_utils_ut.c:354:31: warning: ‘/foo/bar’ directive output may be truncated writing 8 bytes into a region of size between 1 and 4096 [-Wformat-truncation=]
  354 |     snprintf(p2, PATH_MAX, "%s/foo/bar", cwd);
      |                               ^~~~~~~~
...
path_utils/path_utils_ut.c:302:31: warning: ‘/foo’ directive output may be truncated writing 4 bytes into a region of size between 1 and 4096 [-Wformat-truncation=]
  302 |     snprintf(p2, PATH_MAX, "%s/foo", cwd);
      |                               ^~~~
```

Reviewed-by: Sumit Bose <[email protected]>
  • Loading branch information
alexey-tikhonov committed Jan 21, 2022
1 parent cfecd70 commit 83d9cc5
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions path_utils/path_utils_ut.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,14 +292,16 @@ START_TEST(test_make_path_absolute)
char cwd[PATH_MAX];
char *buf;
size_t buf_len;
int res;

fail_unless(make_path_absolute(p, PATH_MAX, "/foo") == SUCCESS);
fail_unless_str_equal(p, "/foo");

fail_if(getcwd(cwd, PATH_MAX) == NULL, "getcwd failed");

fail_unless(make_path_absolute(p, PATH_MAX, "foo") == SUCCESS);
snprintf(p2, PATH_MAX, "%s/foo", cwd);
res = snprintf(p2, PATH_MAX, "%s/foo", cwd);
fail_if((res < 0) || (res >= PATH_MAX));
fail_unless_str_equal(p, p2);

fail_unless(make_path_absolute(p, PATH_MAX, "") == SUCCESS);
Expand Down Expand Up @@ -347,11 +349,13 @@ START_TEST(test_make_normalized_absolute_path)
char p[PATH_MAX];
char p2[PATH_MAX];
char cwd[PATH_MAX];
int res;

fail_if(getcwd(cwd, PATH_MAX) == NULL, "getcwd failed");

fail_unless(make_normalized_absolute_path(p, PATH_MAX, "foo/baz/../bar") == SUCCESS);
snprintf(p2, PATH_MAX, "%s/foo/bar", cwd);
res = snprintf(p2, PATH_MAX, "%s/foo/bar", cwd);
fail_if((res < 0) || (res >= PATH_MAX));
fail_unless_str_equal(p, p2);

fail_unless(make_normalized_absolute_path(p, PATH_MAX, "/foo/../bar") == SUCCESS);
Expand Down

0 comments on commit 83d9cc5

Please sign in to comment.