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

    <tr>
        <th>Summary</th>
        <td>
            regression: false positive from `clang-analyzer-unix.StdCLibraryFunctions` with `getcwd()`
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            false-positive
      </td>
    </tr>

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

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

<pre>
    clang-tidy / clang static analyzer tells me:

```
warning: The 1st argument to 'getcwd' is NULL but should not be NULL [clang-analyzer-unix.StdCLibraryFunctions]

         char* currentPath = getcwd(nullptr, 0);
                             ^
```

But the macOS man page for getcwd says:

"If buf is NULL [1st param], space is allocated as necessary to store the pathname and size [2nd param] is ignored.  This space may later be free(3)'d."

Looks like the responsible line is : https://github.com/llvm/llvm-project/blob/defe43bbffb0d25ec468f0e54b20548ec192ff90/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp#L2662C1-L2662C46

from this commit: https://github.com/llvm/llvm-project/commit/7dd20637c801b429f2dd1040941d00141459d64e

from this PR: https://github.com/llvm/llvm-project/pull/77040

@benshi001
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJycVF2PpDYQ_DXmpbUj05iPeeBhdjdIkUbJKXv5AQY34KyxkW12M_frIzMze9EqD7mzLFlguqqrKLUMQU-WqGXlIyufM7nF2fk2kLRL1jt1aQcj7fQQtboAww72RwhRRj2AtNJcvpGHSMYEWIgVJ8b3XfHb5qd36a22EytO8HUmyEME6adtIRshOmBYTxSHd8WwBh3gtz_PZ-i3CGF2m1FgXYSerq9Z-Xjt5878sFn99-Elqqez7r30l26zQ9TOBlY-X1uB-xpm6RmeYNi8Jxu_yDgDK57hzt7YzZg1eoZPwBkeWfH47_L_Wqz85ZNYxk-PW4Q4Eyxy-P0FFmlhlRPB6PyNCoK8hO9WIf46Qr-NH-JZ-ZhMWqWXS5KBTxBWOVD6QBrjBhlJgQxgaaAQpL8kH0N0nnbiVcbZyoVAWgVBf6OEiFZ9ICYgPVnnSR0Avs463AgWeQEjI_nk-OiJGDZFsgJrdWCI147Pzr0GMPr1SucprM4G3RsCo-3eZvrZc4zrLhM7ht2k47z1h8EtDDtj3u7Hw-rdXzREhl1vXM-wUzSSKPp-HHuusKRBVM3IqRQ98lI0NORHHMcjZ9jtYUhAOhW-7Kk83aLBsHuaaXglH_Y79Tkht9vDsK4MizNWFT7lD9dTVFepo3cLxGTQ4JZFx5_SdSvFrlYKeVXUQ8PzXuBxRKVyLvhR5IrzXOSiPKpK0GfuL3_8FO-6GZNYay5u0WSC92TDrDnPM9UW6lgcZUZtXgteNvxYVtnclmMj5VjnfcmRF3VR15xGWfO8GcuiqOpMt8ix5IhVLgQW1SFXFVdCjpUoyrJHwQSnRWpzSA0dnJ8yHcJGbY5N02BmZE8m7CMHcZQm0MPqgo76jVLGyufMt7uUfpsCE9zoEMN3rKijodbT5CkE7WzyZkeBOwrs1rGK_-9hUXF412keVPxjHKTcVzzbvGl_2Ppdb8rdTfJbi_8EAAD__0Xzs0s">