[Bug c/96832] New: Wrong assumption for -Werror=nonnull check
jernej.skrabec at siol dot net
gcc-bugzilla@gcc.gnu.org
Fri Aug 28 09:24:04 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96832
Bug ID: 96832
Summary: Wrong assumption for -Werror=nonnull check
Product: gcc
Version: 10.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: jernej.skrabec at siol dot net
Target Milestone: ---
Following code:
#include <stdlib.h>
#include <unistd.h>
int main()
{
char *path = getcwd(0, 4096);
free(path);
return 0;
}
Fails to compile with -Wall -Werror with:
main.c: In function ‘main’:
main.c:5:15: error: argument 1 is null but the corresponding size argument 2
value is 4096 [-Werror=nonnull]
5 | char *path = getcwd(0, 4096);
| ^~~~~~~~~~~~~~~
In file included from main.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: all warnings being treated as errors
even though it's correct according to
https://man7.org/linux/man-pages//man2/getcwd.2.html for glibc, which have
extension for exactly this case.
This was tested with gcc 10.2.0 and glibc 2.32 on Arch Linux. Code in question
comes from nss library.
More information about the Gcc-bugs
mailing list