[PATCH] fixincludes: don't assume getcwd() can handle NULL argument

Joseph Myers joseph@codesourcery.com
Wed Nov 10 00:02:10 GMT 2021

On Tue, 9 Nov 2021, Xi Ruoyao via Gcc-patches wrote:

> POSIX says:
>     On some implementations, if buf is a null pointer, getcwd() may obtain
>     size bytes of memory using malloc(). In this case, the pointer returned
>     by getcwd() may be used as the argument in a subsequent call to free().
>     Invoking getcwd() with buf as a null pointer is not recommended in
>     conforming applications.
> This produces an error building GCC with --enable-werror-always:
>     ../../../fixincludes/fixincl.c: In function ‘process’:
>     ../../../fixincludes/fixincl.c:1356:7: error: argument 1 is null but
>     the corresponding size argument 2 value is 4096 [-Werror=nonnull]

Isn't this warning actually a glibc bug 

Joseph S. Myers

More information about the Gcc-patches mailing list