Skip to content

Conversation

Pineapple-Soup
Copy link

Fixes #4380

  • Use pathname[len-1] instead of pathname[len] to compare/modify last character instead of null terminator
  • Move len == 0 check to inside loop to avoid OOB

@meta-cla meta-cla bot added the CLA Signed label Aug 5, 2025
@Pineapple-Soup Pineapple-Soup marked this pull request as ready for review August 5, 2025 20:31
@Cyan4973 Cyan4973 self-assigned this Aug 13, 2025
/* get dir name from pathname similar to 'dirname()' */
assert(pathname != NULL);

/* remove trailing '/' chars */
Copy link
Contributor

@Cyan4973 Cyan4973 Aug 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be fair, I'm not sure if this part of the code makes sense.

The goal of the method convertPathnameToDirName() is to convert a full path of a filename into a just its directory part.

But if pathname ends with a / character, then it already represents a directory name.
In which case, there should be no need to change anything.

In contrast, if we remove the last /, the next stage would strip the last part of the path, and we would end up with the upper directory. And I suspect that's not the wanted behavior.

At this point, my suspicion is that this paragraph is useless, and should just be removed. "Fixing" it could actually introduce problems.

Note: a good follow up could be to improve the tests, by finding scenarios that introduce problems if this function is badly defined. Since our CI signal is all-greens, that means it does not capture the issue.

Copy link

@Ari4ka Ari4ka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants