Skip to content

regression: false positive from clang-analyzer-unix.StdCLibraryFunctions with getcwd() #128882

@seanm

Description

@seanm

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: 7dd2063

from this PR: #77040

@benshi001

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions