facebook / facebook/zstd

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

Open
#4,380 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
27.9k
Forks
2.6k
Avg merge
1d 3h
Merged PRs (30d)
8

Description

**Describe the bug**
In `convertPathnameToDirName()`, the code attempts to remove trailing `/` characters with:
```c
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/"`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.