Extracted from https://github.com/libarchive/libarchive/issues/1498. Small example: $ cat a.c #include <limits.h> /* PATH_MAX */ #include <unistd.h> /* getcwd() */ // from https://github.com/libarchive/libarchive/issues/1498 char * bug(void) { return getcwd(NULL, PATH_MAX);/* Solaris getcwd needs the size. */ } $ gcc-10.2.0 -O2 -c a.c -O2 -Wall -Werror=nonnull -D_FORTIFY_SOURCE=0 <command-line>: warning: "_FORTIFY_SOURCE" redefined <built-in>: note: this is the location of the previous definition a.c: In function 'bug': a.c:6:12: error: argument 1 is null but the corresponding size argument 2 value is 4096 [-Werror=nonnull] 6 | return getcwd(NULL, PATH_MAX);/* Solaris getcwd needs the size. */ | ^~~~~~~~~~~~~~~~~~~~~~ In file included from a.c:2: /usr/include/unistd.h:520:14: note: in a call to function 'getcwd' declared with attribute 'write_only (1, 2)' 520 | extern char *getcwd (char *__buf, size_t __size) __THROW __wur | ^~~~~~ cc1: some warnings being treated as errors I see https://sourceware.org/PR26545 where there is a discussion of possibly changing the behaviour of the function. I'm opening the bug to consider at least removing the warning whic the behaviour is valid Thanks!.
Proposed patch here: https://sourceware.org/pipermail/libc-alpha/2021-September/130857.html