Skip to content

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

Open
@mugitya03

Description

@mugitya03

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/".

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions