likle / cwalk

Path library for C/C++. Cross-Platform for Linux, FreeBSD, Windows and MacOS. Supports UNIX and Windows path styles on those platforms.
https://likle.github.io/cwalk/
MIT License
250 stars 39 forks source link

cwk_path_get_relative segfaulted #17

Closed winterland1989 closed 3 years ago

winterland1989 commented 3 years ago

cwk_path_get_relative is buggy if:

likle commented 3 years ago

Hi @winterland1989 ! Thanks for submitting this, I will have a look at it.

likle commented 3 years ago

What result would you expect in the first case? "./bar"?

winterland1989 commented 3 years ago

After reading the source, I found in the first case the return value is 0, so it's not cwalk's problem, maybe writing a NULL byte to the buffer? Anyway please add some documents about this behavior.

The second case is definitely is a bug.

likle commented 3 years ago

Absolutely, I can reproduce it and will fix it as soon as possible.

likle commented 3 years ago

As the documentation says, the result should always be null terminated. So both cases were bugs and have been fixed on the master branch. Please let me know if something doesnt work as expected!

winterland1989 commented 3 years ago

Thank you! I have tested the new code, there is still a problem I think: cwk_path_get_relative("./foo", "/bar", ...) doesn't return 0(which i think it should).

likle commented 3 years ago

Oh no! you are right - I fixed that as well.