Skip to content

Commit

Permalink
Avoid duplicating the path separator.
Browse files Browse the repository at this point in the history
  • Loading branch information
dag-erling committed Sep 10, 2024
1 parent 78b7a5d commit dcdcf78
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions test_utils/test_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3888,6 +3888,7 @@ main(int argc, char **argv)
int test_set[limit];
int i = 0, j = 0, tests_run = 0, tests_failed = 0, option;
size_t testprogdir_len;
size_t tmplen;
#ifdef PROGRAM
size_t tmp2_len;
#endif
Expand Down Expand Up @@ -3987,6 +3988,9 @@ main(int argc, char **argv)
tmp = getenv("TEMPDIR");
else
tmp = "/tmp";
tmplen = strlen(tmp);
while (tmplen > 0 && tmp[tmplen - 1] == '/')
tmplen--;

/* Allow -d to be controlled through the environment. */
if (getenv(ENVBASE "_DEBUG") != NULL)
Expand Down Expand Up @@ -4139,16 +4143,16 @@ main(int argc, char **argv)
#endif
strftime(tmpdir_timestamp, sizeof(tmpdir_timestamp),
"%Y-%m-%dT%H.%M.%S", tmptr);
if ((strlen(tmp) + 1 + strlen(progname) + 1 +
strlen(tmpdir_timestamp) + 1 + 3) >
if (tmplen + 1 + strlen(progname) + 1 +
strlen(tmpdir_timestamp) + 1 + 3 >=
sizeof(tmpdir)) {
fprintf(stderr,
"ERROR: Temp directory pathname too long\n");
exit(1);
}
snprintf(tmpdir, sizeof(tmpdir), "%s/%s.%s-%03d", tmp,
progname, tmpdir_timestamp, i);
if (assertMakeDir(tmpdir,0755))
snprintf(tmpdir, sizeof(tmpdir), "%.*s/%s.%s-%03d",
(int)tmplen, tmp, progname, tmpdir_timestamp, i);
if (assertMakeDir(tmpdir, 0755))
break;
if (i >= 999) {
fprintf(stderr,
Expand Down

0 comments on commit dcdcf78

Please sign in to comment.