<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/152704>152704</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            horiffic getMainExecutable() code
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          marotc
      </td>
    </tr>
</table>

<pre>
    I just stumbled on [this function](https://github.com/llvm/llvm-project/blob/main/llvm/lib/Support/Unix/Path.inc#L191) where the address of a static array is returned repeatedly like so:
```c
char link_path[PATH_MAX];
if (realpath(exe_path, link_path))
 return link_path;
```

If you know a little bit of C, it should make you uncomfortable reading that function as this is just plain wrong: the link_path array is out of scope as soon as the function returns.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyUUl1r4zoQ_TXyy3CDo9ix_eAHp73hFm6hsLuwb2UkTWI1imSkUdP8-8VOv14XBiQ0R2fOzBxMyR49US_qnajvC8w8htifMQbWhQrm2j_AS04MifNZOTIQPIh6x6NNcMhesw1e1PdCtiPzlMRmEHIv5P5oecxqpcNZyL1zrx_HP1MML6RZyL1yQQm5P6P13zB2fvuRpynEGfTL2zch90_I48p6LeTm_3W3FrKDy0iRgEcCNCZSShAOgJAY2WrAGPEKNkEkztGTgUgTIZNxV3D2RJDCLLYcxLa8hRbloEeM4Kw_PU_Io6h3T8PP_54fh99zj5udKAd7ACHbSOgWhGzpjW5gefftp-zmKIf3-t8yC8tn0fleDg8HuIYMJx8ugOAssyNQlueW7mZiy5DGkJ2BM55oAWevw_kQIqNyBJHQWH8EHpE_FwOYYNmUTbctTg6th0sM_ig2wzK8T2FfIwt5KZx0mGimSOGDir6ob32lVWH6jek2HRbUr5u62taN3Mpi7A0aY7Spms6ohpq13rTUbitS1K1xa7rC9rKUddmW7VpWTSVXW1XXdasaVJ1ShFtRlXRG61azN1YhHgubUqZ-XcumrAqHilxarCulpwssWSHl7OTYL25T-ZhEVTqbOH3RsGVH_RiiPRyshiPxI1r_7xvpvExTyHZ2mA6Gihxd_9fWXpQkIffvUl97-ScAAP__y2Mgbg">