gpakosz / whereami

Locate the current running executable and the current running module/library on the file system 🔎

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Returned path length is off by one

DanielSWolf opened this issue · comments

According to documentation, the path length returned by wai_getExecutablePath is the actual number of characters without a terminating zero byte. Actually, at least on Windows, the value returned includes the trailing zero byte.

This can lead to bugs. For instance, when creating a string like this:

std::string path(buffer, length);

The result is a string with length length that (wrongly) contains a zero character as part of the string.

I see two possible solutions. If all platforms consistently add the zero byte, just the documentation needs to be changed. Otherwise, the individual implementations should be changed to behave consistently.

I believe that's addressed by ba75d51 that fixes #5?

Consider this a duplicate.

Sorry for the inconvenience