[LLVMdev] Some fixes for the GetMainExecutable function

Dan Gohman gohman at apple.com
Thu Sep 2 10:51:51 PDT 2010


On Sep 2, 2010, at 10:03 AM, Kees van Reeuwijk wrote:

> -  snprintf(buf, PATH_MAX, "%s//%s", dir, bin);

There's no comment, and no mention in the commit message.
It seems pretty safe to fix.

> Also, the if-all-else-fails return value of GetMainExecutable is an empty path, but since the users of this function don't test for that, this choice leads to rather obscure errors. Wouldn't it be better to give an explicit error in such cases,

Issuing an error is hard to do right here, since it's in such a low-level
library. However, it doesn't have very many users, and at least some of
them already do handle this error gracefully, so can any users which 
don't be fixed?

> or at the very least to return a path just containing Arg0 rather than the empty string?

If GetMainExecutable ever were to actually fail, it would mean that
something is seriously wrong with the system, so it's quite acceptable
to just fail, rather than cast about.

Dan





More information about the llvm-dev mailing list