https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96916
Bug ID: 96916 Summary: warning: ‘strndup’ specified bound 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Wstringop-overflow=] Product: gcc Version: 10.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: rjones at redhat dot com Target Milestone: --- I'm not certain this is really a bug, but I don't understand it. A simple reproducer: ---------------------------------------------------------------------- #include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <string.h> const char * copyn (const char *str, size_t n) { return strndup (str, n); } const char * copy (const char *str) { return copyn (str, SIZE_MAX); } ---------------------------------------------------------------------- $ gcc -O2 -Wall -c test.c In function ‘copyn’, inlined from ‘copy’ at test.c:15:10: test.c:9:10: warning: ‘strndup’ specified bound 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Wstringop-overflow=] 9 | return strndup (str, n); | ^~~~~~~~~~~~~~~~ $ gcc --version gcc (GCC) 10.2.1 20200826 (Red Hat 10.2.1-3) Copyright (C) 2020 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Note that it seems as if the compiler is claiming that strndup cannot cope with a string larger than ssize_t (rather than size_t), which is unexpected.