zstd icon indicating copy to clipboard operation
zstd copied to clipboard

`convertPathnameToDirName` fails to strip trailing slashes due to off‑by‑one index

Open mugitya03 opened this issue 8 months ago • 0 comments

Describe the bug In convertPathnameToDirName(), the code attempts to remove trailing / characters with:

len = strlen(pathname);
while (pathname[len] == PATH_SEP) {
    pathname[len] = '\0';
    len--;
}

However, strlen(pathname) is the index of the terminating NUL. As a result pathname[len] is always '\0', never '/', so the loop never runs and trailing slashes remain.

To Reproduce

  1. Call convertPathnameToDirName("foo/bar/").
  2. Expect "foo/bar", but function returns "foo/bar/".

mugitya03 avatar May 04 '25 19:05 mugitya03