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

Open Beginner friendly
#4,380 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
c
Domain
backend

Research direction

Search the zstd C sources for convertPathnameToDirName() and inspect the trailing-slash handling described in the issue. Reproduce it with the "foo/bar/" input, then run the relevant existing test or add a focused check to confirm the returned pathname is "foo/bar".

Written by the indexing model from the issue text.

Description

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/".
Dominant language
C
Stars
27.9k
Forks
2.6k
Avg merge
1d 3h
Merged PRs (30d)
8

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from facebook/zstd

All issues in facebook/zstd

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.