Mercurial > hg > octave-lojdl > gnulib-hg
changeset 12422:f7842310a565
New module 'arg-nonnull'. Declare which arguments expect non-NULL values.
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,164 @@ +2009-12-10 Bruno Haible <bruno@clisp.org> + + Declare which arguments expect non-NULL values, for GCC and clang. + * build-aux/arg-nonnull.h: New file. + * modules/arg-nonnull: New file. + * lib/arpa_inet.in.h (_GL_ARG_NONNULL): New placeholder. + (inet_ntop, inet_pton): Use it. + * lib/dirent.in.h (_GL_ARG_NONNULL): New placeholder. + (closedir, dirfd, opendir, scandir, alphasort): Use it. + * lib/fcntl.in.h (_GL_ARG_NONNULL): New placeholder. + (open, openat): Use it. + * lib/fnmatch.in.h (_GL_ARG_NONNULL): New placeholder. + (fnmatch): Use it. + * lib/getopt.in.h (_GL_ARG_NONNULL): New placeholder. + (getopt, getopt_long, getopt_long_only): Use it. + * lib/glob.in.h (_GL_ARG_NONNULL): New placeholder. + * lib/glob-libc.h (glob, globfree, glob64, globfree64, glob_pattern_p): + Use it. + * lib/iconv.in.h (_GL_ARG_NONNULL): New placeholder. + (iconv_open): Use it. + * lib/inttypes.in.h (_GL_ARG_NONNULL): New placeholder. + (strtoimax, strtoumax): Use it. + * lib/locale.in.h (_GL_ARG_NONNULL): New placeholder. + (duplocale): Use it. + * lib/math.in.h (_GL_ARG_NONNULL): New placeholder. + (frexp, frexpl): Use it. + * lib/netdb.in.h (_GL_ARG_NONNULL): New placeholder. + (getaddrinfo, freeaddrinfo, getnameinfo): Use it. + * lib/search.in.h (_GL_ARG_NONNULL): New placeholder. + (tsearch, tfind, tdelete, twalk): Use it. + * lib/signal.in.h (_GL_ARG_NONNULL): New placeholder. + (sigismember, sigemptyset, sigaddset, sigdelset, sigfillset, + sigpending): Use it. + * lib/spawn.in.h (_GL_ARG_NONNULL): New placeholder. + (posix_spawn, posix_spawnp, posix_spawnattr_init, + posix_spawnattr_destroy, posix_spawnattr_getsigdefault, + posix_spawnattr_setsigdefault, posix_spawnattr_getsigmask, + posix_spawnattr_setsigmask, posix_spawnattr_getflags, + posix_spawnattr_setflags, posix_spawnattr_getpgroup, + posix_spawnattr_setpgroup, posix_spawnattr_getschedpolicy, + posix_spawnattr_setschedpolicy, posix_spawnattr_getschedparam, + posix_spawnattr_setschedparam, posix_spawn_file_actions_init, + posix_spawn_file_actions_destroy, posix_spawn_file_actions_addopen, + posix_spawn_file_actions_addclose, posix_spawn_file_actions_adddup2): + Use it. + * lib/stdio.in.h (_GL_ARG_NONNULL): New placeholder. + (dprintf, fclose, fopen, fprintf, fpurge, fputc, fputs, freopen, + rpl_fseek, fseeko, rpl_ftell, ftello, fwrite, getdelim, getline, + obstack_printf, obstack_vprintf, popen, printf, putc, puts, remove, + rename, renameat, snprintf, sprintf, asprintf, vasprintf, vdprintf, + vfprintf, vprintf, vsnprintf, vsprintf): Use it. + * lib/stdlib.in.h (_GL_ARG_NONNULL): New placeholder. + (atoll, canonicalize_file_name, getloadavg, getsubopt, mkdtemp, + mkostemp, mkostemps, mkstemp, mkstemps, putenv, srandom_r, initstate_r, + setstate_r, random_r, realpath, rpmatch, setenv, strtod, strtoll, + strtoull, unsetenv): Use it. + * lib/string.in.h (_GL_ARG_NONNULL): New placeholder. + (memchr, memmem, mempcpy, memrchr, rawmemchr, stpcpy, stpncpy, + strchrnul, strdup, strndup, strnlen, strpbrk, strsep, strstr, + strcasestr, strtok_r, mbslen, mbsnlen, mbschr, mbsrchr, mbsstr, + mbscasecmp, mbsncasecmp, mbspcasecmp, mbscasestr, mbscspn, mbspbrk, + mbsspn, mbssep, mbstok_r, strverscmp): Use it. + * lib/strings.in.h (_GL_ARG_NONNULL): New placeholder. + (strcasecmp, strncasecmp): Use it. + * lib/sys_socket.in.h (_GL_ARG_NONNULL): New placeholder. + (rpl_connect, rpl_bind, rpl_getpeername, rpl_getsockname, + rpl_getsockopt, rpl_recv, rpl_send, rpl_recvfrom, rpl_sendto, + rpl_setsockopt): Use it. + * lib/sys_stat.in.h (_GL_ARG_NONNULL): New placeholder. + (fchmodat, fstat, fstatat, lchmod, rpl_lstat, mkdir, mkdirat, mkfifo, + mkfifoat, mknod, mknodat, stat, utimensat): Use it. + * lib/sys_time.in.h (_GL_ARG_NONNULL): New placeholder. + (gettimeofday): Use it. + * lib/sys_times.in.h (_GL_ARG_NONNULL): New placeholder. + (times): Use it. + * lib/sys_utsname.in.h (_GL_ARG_NONNULL): New placeholder. + (uname): Use it. + * lib/time.in.h (_GL_ARG_NONNULL): New placeholder. + (nanosleep, mktime, localtime_r, gmtime_r, strptime, timegm): Use it. + * lib/unistd.in.h (_GL_ARG_NONNULL): New placeholder. + (chown, euidaccess, faccessat, _gl_register_fd, fchownat, + getdomainname, gethostname, getlogin_r, lchown, link, linkat, pipe2, + pread, readlink, readlinkat, rmdir, symlink, symlinkat, unlink, + unlinkat, write): Use it. + * lib/wchar.in.h (_GL_ARG_NONNULL): New placeholder. + (mbsrtowcs, mbsnrtowcs, wcsrtombs, wcsnrtombs): Use it. + * lib/argv-iter.h: Include arg-nonnull.h. + (_ATTRIBUTE_NONNULL_): Remove macro. + (argv_iter_init_argv, argv_iter_init_stream, argv_iter, + argv_iter_n_args, argv_iter_free): Use _GL_ARG_NONNULL. + * lib/canonicalize-lgpl.c (_GL_ARG_NONNULL): Define, to defeat gcc + optimization. + * lib/getaddrinfo.c (_GL_ARG_NONNULL): Likewise. + * lib/getdelim.c (_GL_ARG_NONNULL): Likewise. + * lib/glob.c (_GL_ARG_NONNULL): Likewise. + * lib/random_r.c (_GL_ARG_NONNULL): Likewise. + * lib/setenv.c (_GL_ARG_NONNULL): Likewise. + * lib/strtod.c (_GL_ARG_NONNULL): Likewise. + * lib/tsearch.c (_GL_ARG_NONNULL): Likewise. + * lib/unsetenv.c (_GL_ARG_NONNULL): Likewise. + * modules/arpa_inet (Depends-on): Add arg-nonnull. + (Makefile.am): Insert arg-nonnull.h into arpa/inet.h. + * modules/dirent (Depends-on): Add arg-nonnull. + (Makefile.am): Insert arg-nonnull.h into dirent.h. + * modules/fcntl-h (Depends-on): Add arg-nonnull. + (Makefile.am): Insert arg-nonnull.h into fcntl.h. + * modules/fnmatch (Depends-on): Add arg-nonnull. + (Makefile.am): Insert arg-nonnull.h into fnmatch.h. + * modules/getopt-posix (Depends-on): Add arg-nonnull. + (Makefile.am): Insert arg-nonnull.h into getopt.h. + * modules/glob (Depends-on): Add arg-nonnull. + (Makefile.am): Insert arg-nonnull.h into glob.h. + * modules/iconv_open (Depends-on): Add arg-nonnull. + (Makefile.am): Insert arg-nonnull.h into iconv.h. + * modules/inttypes (Depends-on): Add arg-nonnull. + (Makefile.am): Insert arg-nonnull.h into inttypes.h. + * modules/locale (Depends-on): Add arg-nonnull. + (Makefile.am): Insert arg-nonnull.h into locale.h. + * modules/math (Depends-on): Add arg-nonnull. + (Makefile.am): Insert arg-nonnull.h into math.h. + * modules/netdb (Depends-on): Add arg-nonnull. + (Makefile.am): Insert arg-nonnull.h into netdb.h. + * modules/search (Depends-on): Add arg-nonnull. + (Makefile.am): Insert arg-nonnull.h into search.h. + * modules/signal (Depends-on): Add arg-nonnull. + (Makefile.am): Insert arg-nonnull.h into signal.h. + * modules/spawn (Depends-on): Add arg-nonnull. + (Makefile.am): Insert arg-nonnull.h into spawn.h. + * modules/stdio (Depends-on): Add arg-nonnull. + (Makefile.am): Insert arg-nonnull.h into stdio.h. + * modules/stdlib (Depends-on): Add arg-nonnull. + (Makefile.am): Insert arg-nonnull.h into stdlib.h. + * modules/string (Depends-on): Add arg-nonnull. + (Makefile.am): Insert arg-nonnull.h into string.h. + * modules/strings (Depends-on): Add arg-nonnull. + (Makefile.am): Insert arg-nonnull.h into strings.h. + * modules/sys_socket (Depends-on): Add arg-nonnull. + (Makefile.am): Insert arg-nonnull.h into sys/socket.h. + * modules/sys_stat (Depends-on): Add arg-nonnull. + (Makefile.am): Insert arg-nonnull.h into sys/stat.h. + * modules/sys_time (Depends-on): Add arg-nonnull. + (Makefile.am): Insert arg-nonnull.h into sys/time.h. + * modules/sys_times (Depends-on): Add arg-nonnull. + (Makefile.am): Insert arg-nonnull.h into sys/times.h. + * modules/sys_utsname (Depends-on): Add arg-nonnull. + (Makefile.am): Insert arg-nonnull.h into sys/utsname.h. + * modules/time (Depends-on): Add arg-nonnull. + (Makefile.am): Insert arg-nonnull.h into time.h. + * modules/unistd (Depends-on): Add arg-nonnull. + (Makefile.am): Insert arg-nonnull.h into unistd.h. + * modules/wchar (Depends-on): Add arg-nonnull. + (Makefile.am): Insert arg-nonnull.h into wchar.h. + * modules/argv-iter (Depends-on): Add arg-nonnull. + * tests/test-canonicalize.c (null_ptr): New function. + (main): Use it. + * tests/test-canonicalize-lgpl.c (null_ptr): New function. + (main): Use it. + * tests/test-memmem.c (null_ptr): New function. + (main): Use it. + Reported by Jim Meyering. + 2009-12-10 Bruno Haible <bruno@clisp.org> Use spaces for indentation, not tabs.
new file mode 100644 --- /dev/null +++ b/build-aux/arg-nonnull.h @@ -0,0 +1,26 @@ +/* A C macro for declaring that specific arguments must not be NULL. + Copyright (C) 2009 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published + by the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +/* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools + that the values passed as arguments n, ..., m must be non-NULL pointers. + n = 1 stands for the first argument, n = 2 for the second argument etc. */ +#ifndef _GL_ARG_NONNULL +# if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ > 3 +# define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params)) +# else +# define _GL_ARG_NONNULL(params) +# endif +#endif
--- a/lib/argv-iter.h +++ b/lib/argv-iter.h @@ -17,16 +17,12 @@ #include <stdio.h> #include <stdbool.h> +/* Definition of _GL_ARG_NONNULL. */ +#include "arg-nonnull.h" + struct argv_iterator; enum argv_iter_err; -#undef _ATTRIBUTE_NONNULL_ -#if __GNUC__ == 3 && __GNUC_MINOR__ >= 3 || 3 < __GNUC__ -# define _ATTRIBUTE_NONNULL_(m) __attribute__ ((__nonnull__ (m))) -#else -# define _ATTRIBUTE_NONNULL_(m) -#endif - enum argv_iter_err { AI_ERR_OK = 1, @@ -36,12 +32,12 @@ }; struct argv_iterator *argv_iter_init_argv (char **argv) - _ATTRIBUTE_NONNULL_ (1); + _GL_ARG_NONNULL ((1)); struct argv_iterator *argv_iter_init_stream (FILE *fp) - _ATTRIBUTE_NONNULL_ (1); + _GL_ARG_NONNULL ((1)); char *argv_iter (struct argv_iterator *, enum argv_iter_err *) - _ATTRIBUTE_NONNULL_ (1) _ATTRIBUTE_NONNULL_ (2); + _GL_ARG_NONNULL ((1, 2)); size_t argv_iter_n_args (struct argv_iterator const *) - _ATTRIBUTE_NONNULL_ (1); + _GL_ARG_NONNULL ((1)); void argv_iter_free (struct argv_iterator *) - _ATTRIBUTE_NONNULL_ (1); + _GL_ARG_NONNULL ((1));
--- a/lib/arpa_inet.in.h +++ b/lib/arpa_inet.in.h @@ -1,6 +1,6 @@ /* A GNU-like <arpa/inet.h>. - Copyright (C) 2005-2006, 2008 Free Software Foundation, Inc. + Copyright (C) 2005-2006, 2008-2009 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -38,6 +38,8 @@ /* The definition of GL_LINK_WARNING is copied here. */ +/* The definition of _GL_ARG_NONNULL is copied here. */ + #ifdef __cplusplus extern "C" { #endif @@ -60,7 +62,8 @@ For more details, see the POSIX:2001 specification <http://www.opengroup.org/susv3xsh/inet_ntop.html>. */ extern const char *inet_ntop (int af, const void *restrict src, - char *restrict dst, socklen_t cnt); + char *restrict dst, socklen_t cnt) + _GL_ARG_NONNULL ((2, 3)); # endif #elif defined GNULIB_POSIXCHECK # undef inet_ntop @@ -72,7 +75,8 @@ #if @GNULIB_INET_PTON@ # if !@HAVE_DECL_INET_PTON@ -extern int inet_pton (int af, const char *restrict src, void *restrict dst); +extern int inet_pton (int af, const char *restrict src, void *restrict dst) + _GL_ARG_NONNULL ((2, 3)); # endif #elif defined GNULIB_POSIXCHECK # undef inet_pton
--- a/lib/canonicalize-lgpl.c +++ b/lib/canonicalize-lgpl.c @@ -21,6 +21,10 @@ #if !HAVE_CANONICALIZE_FILE_NAME || !FUNC_REALPATH_WORKS || defined _LIBC +/* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc + optimizes away the name == NULL test below. */ +#define _GL_ARG_NONNULL(params) + /* Specification. */ #include <stdlib.h>
--- a/lib/dirent.in.h +++ b/lib/dirent.in.h @@ -28,6 +28,8 @@ /* The definition of GL_LINK_WARNING is copied here. */ +/* The definition of _GL_ARG_NONNULL is copied here. */ + #ifdef __cplusplus extern "C" { @@ -37,14 +39,14 @@ #if @REPLACE_CLOSEDIR@ # define closedir rpl_closedir -extern int closedir (DIR *); +extern int closedir (DIR *) _GL_ARG_NONNULL ((1)); #endif #if @GNULIB_DIRFD@ # if !@HAVE_DECL_DIRFD@ && !defined dirfd /* Return the file descriptor associated with the given directory stream, or -1 if none exists. */ -extern int dirfd (DIR const *dir); +extern int dirfd (DIR const *dir) _GL_ARG_NONNULL ((1)); # endif #elif defined GNULIB_POSIXCHECK # undef dirfd @@ -77,7 +79,7 @@ #if @REPLACE_OPENDIR@ # define opendir rpl_opendir -extern DIR * opendir (const char *); +extern DIR * opendir (const char *) _GL_ARG_NONNULL ((1)); #endif #if @GNULIB_SCANDIR@ @@ -88,7 +90,8 @@ # if !@HAVE_SCANDIR@ extern int scandir (const char *dir, struct dirent ***namelist, int (*filter) (const struct dirent *), - int (*cmp) (const struct dirent **, const struct dirent **)); + int (*cmp) (const struct dirent **, const struct dirent **)) + _GL_ARG_NONNULL ((1, 2, 4)); # endif #elif defined GNULIB_POSIXCHECK # undef scandir @@ -101,7 +104,8 @@ #if @GNULIB_ALPHASORT@ /* Compare two 'struct dirent' entries alphabetically. */ # if !@HAVE_ALPHASORT@ -extern int alphasort (const struct dirent **, const struct dirent **); +extern int alphasort (const struct dirent **, const struct dirent **) + _GL_ARG_NONNULL ((1, 2)); # endif #elif defined GNULIB_POSIXCHECK # undef alphasort
--- a/lib/fcntl.in.h +++ b/lib/fcntl.in.h @@ -46,6 +46,8 @@ /* The definition of GL_LINK_WARNING is copied here. */ +/* The definition of _GL_ARG_NONNULL is copied here. */ + /* Declare overridden functions. */ @@ -57,7 +59,7 @@ # if @REPLACE_OPEN@ # undef open # define open rpl_open -extern int open (const char *filename, int flags, ...); +extern int open (const char *filename, int flags, ...) _GL_ARG_NONNULL ((1)); # endif #endif @@ -67,7 +69,8 @@ # define openat rpl_openat # endif # if !@HAVE_OPENAT@ || @REPLACE_OPENAT@ -int openat (int fd, char const *file, int flags, /* mode_t mode */ ...); +int openat (int fd, char const *file, int flags, /* mode_t mode */ ...) + _GL_ARG_NONNULL ((2)); # endif #elif defined GNULIB_POSIXCHECK # undef openat
--- a/lib/fnmatch.in.h +++ b/lib/fnmatch.in.h @@ -1,5 +1,5 @@ /* Copyright (C) 1991, 1992, 1993, 1996, 1997, 1998, 1999, 2001, 2002, 2003, - 2005, 2007 Free Software Foundation, Inc. + 2005, 2007, 2009 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -20,6 +20,8 @@ #ifndef _FNMATCH_H #define _FNMATCH_H 1 +/* The definition of _GL_ARG_NONNULL is copied here. */ + #ifdef __cplusplus extern "C" { #endif @@ -56,7 +58,8 @@ /* Match NAME against the file name pattern PATTERN, returning zero if it matches, FNM_NOMATCH if not. */ extern int fnmatch (const char *__pattern, const char *__name, - int __flags); + int __flags) + _GL_ARG_NONNULL ((1, 2)); #ifdef __cplusplus }
--- a/lib/getaddrinfo.c +++ b/lib/getaddrinfo.c @@ -1,6 +1,5 @@ /* Get address information (partial implementation). - Copyright (C) 1997, 2001, 2002, 2004, 2005, 2006, 2007, 2008 Free Software - Foundation, Inc. + Copyright (C) 1997, 2001-2002, 2004-2009 Free Software Foundation, Inc. Contributed by Simon Josefsson <simon@josefsson.org>. This program is free software; you can redistribute it and/or modify @@ -19,6 +18,10 @@ #include <config.h> +/* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc + optimizes away the sa == NULL test below. */ +#define _GL_ARG_NONNULL(params) + #include <netdb.h> #if HAVE_NETINET_IN_H
--- a/lib/getdelim.c +++ b/lib/getdelim.c @@ -21,6 +21,10 @@ #include <config.h> +/* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc + optimizes away the lineptr == NULL || n == NULL || fp == NULL tests below. */ +#define _GL_ARG_NONNULL(params) + #include <stdio.h> #include <limits.h>
--- a/lib/getopt.in.h +++ b/lib/getopt.in.h @@ -121,6 +121,8 @@ # endif #endif +/* The definition of _GL_ARG_NONNULL is copied here. */ + #ifdef __cplusplus extern "C" { #endif @@ -222,17 +224,17 @@ the environment, then do not permute arguments. */ extern int getopt (int ___argc, char *const *___argv, const char *__shortopts) - __THROW; + __THROW _GL_ARG_NONNULL ((2, 3)); #ifndef __need_getopt extern int getopt_long (int ___argc, char *__getopt_argv_const *___argv, const char *__shortopts, const struct option *__longopts, int *__longind) - __THROW; + __THROW _GL_ARG_NONNULL ((2, 3)); extern int getopt_long_only (int ___argc, char *__getopt_argv_const *___argv, const char *__shortopts, const struct option *__longopts, int *__longind) - __THROW; + __THROW _GL_ARG_NONNULL ((2, 3)); #endif
--- a/lib/glob-libc.h +++ b/lib/glob-libc.h @@ -1,4 +1,4 @@ -/* Copyright (C) 1991,92,95-98,2000,2001,2004-2007 Free Software Foundation, Inc. +/* Copyright (C) 1991,92,95-98,2000,2001,2004-2007, 2009 Free Software Foundation, Inc. This file is part of the GNU C Library. This program is free software: you can redistribute it and/or modify @@ -173,10 +173,10 @@ #if !defined __USE_FILE_OFFSET64 || __GNUC__ < 2 || defined __GLOB_GNULIB extern int glob (const char *_Restrict_ __pattern, int __flags, int (*__errfunc) (const char *, int), - glob_t *_Restrict_ __pglob) __THROW; + glob_t *_Restrict_ __pglob) __THROW _GL_ARG_NONNULL ((1, 4)); /* Free storage allocated in PGLOB by a previous `glob' call. */ -extern void globfree (glob_t *__pglob) __THROW; +extern void globfree (glob_t *__pglob) __THROW _GL_ARG_NONNULL ((1)); #else extern int __REDIRECT_NTH (glob, (const char *_Restrict_ __pattern, int __flags, @@ -189,9 +189,10 @@ #if defined __USE_LARGEFILE64 && !defined __GLOB_GNULIB extern int glob64 (const char *_Restrict_ __pattern, int __flags, int (*__errfunc) (const char *, int), - glob64_t *_Restrict_ __pglob) __THROW; + glob64_t *_Restrict_ __pglob) + __THROW _GL_ARG_NONNULL ((1, 4)); -extern void globfree64 (glob64_t *__pglob) __THROW; +extern void globfree64 (glob64_t *__pglob) __THROW _GL_ARG_NONNULL ((1)); #endif @@ -201,7 +202,8 @@ This function is not part of the interface specified by POSIX.2 but several programs want to use it. */ -extern int glob_pattern_p (const char *__pattern, int __quote) __THROW; +extern int glob_pattern_p (const char *__pattern, int __quote) + __THROW _GL_ARG_NONNULL ((1)); #endif __END_DECLS
--- a/lib/glob.c +++ b/lib/glob.c @@ -19,6 +19,10 @@ # include <config.h> #endif +/* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc + optimizes away the pattern == NULL || pglob == NULL tests below. */ +#define _GL_ARG_NONNULL(params) + #include <glob.h> #include <errno.h>
--- a/lib/glob.in.h +++ b/lib/glob.in.h @@ -1,6 +1,6 @@ /* glob.h -- Find a path matching a pattern. - Copyright (C) 2005-2007 Free Software Foundation, Inc. + Copyright (C) 2005-2007, 2009 Free Software Foundation, Inc. Written by Derek Price <derek@ximbiot.com> & Paul Eggert <eggert@CS.UCLA.EDU> @@ -40,6 +40,8 @@ # define __THROW #endif +/* The definition of _GL_ARG_NONNULL is copied here. */ + #ifndef __size_t # define __size_t size_t #endif
--- a/lib/iconv.in.h +++ b/lib/iconv.in.h @@ -1,6 +1,6 @@ /* A GNU-like <iconv.h>. - Copyright (C) 2007-2008 Free Software Foundation, Inc. + Copyright (C) 2007-2009 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -28,6 +28,8 @@ #ifndef _GL_ICONV_H #define _GL_ICONV_H +/* The definition of _GL_ARG_NONNULL is copied here. */ + #ifdef __cplusplus extern "C" { #endif @@ -37,7 +39,8 @@ /* An iconv_open wrapper that supports the IANA standardized encoding names ("ISO-8859-1" etc.) as far as possible. */ # define iconv_open rpl_iconv_open -extern iconv_t iconv_open (const char *tocode, const char *fromcode); +extern iconv_t iconv_open (const char *tocode, const char *fromcode) + _GL_ARG_NONNULL ((1, 2)); #endif #if @REPLACE_ICONV_UTF@
--- a/lib/inttypes.in.h +++ b/lib/inttypes.in.h @@ -47,6 +47,8 @@ /* The definition of GL_LINK_WARNING is copied here. */ +/* The definition of _GL_ARG_NONNULL is copied here. */ + /* 7.8.1 Macros for format specifiers */ #if ! defined __cplusplus || defined __STDC_FORMAT_MACROS @@ -1066,7 +1068,7 @@ #if @GNULIB_STRTOIMAX@ # if !@HAVE_DECL_STRTOIMAX@ -extern intmax_t strtoimax (const char *, char **, int); +extern intmax_t strtoimax (const char *, char **, int) _GL_ARG_NONNULL ((1)); # endif #elif defined GNULIB_POSIXCHECK # undef strtoimax @@ -1078,7 +1080,7 @@ #if @GNULIB_STRTOUMAX@ # if !@HAVE_DECL_STRTOUMAX@ -extern uintmax_t strtoumax (const char *, char **, int); +extern uintmax_t strtoumax (const char *, char **, int) _GL_ARG_NONNULL ((1)); # endif #elif defined GNULIB_POSIXCHECK # undef strtoumax
--- a/lib/locale.in.h +++ b/lib/locale.in.h @@ -34,6 +34,8 @@ # include <xlocale.h> #endif +/* The definition of _GL_ARG_NONNULL is copied here. */ + /* The LC_MESSAGES locale category is specified in POSIX, but not in ISO C. On systems that don't define it, use the same value as GNU libintl. */ #if !defined LC_MESSAGES @@ -44,7 +46,7 @@ # if @REPLACE_DUPLOCALE@ # undef duplocale # define duplocale rpl_duplocale -extern locale_t duplocale (locale_t locale); +extern locale_t duplocale (locale_t locale) _GL_ARG_NONNULL ((1)); # endif #elif defined GNULIB_POSIXCHECK # undef duplocale
--- a/lib/math.in.h +++ b/lib/math.in.h @@ -30,6 +30,8 @@ /* The definition of GL_LINK_WARNING is copied here. */ +/* The definition of _GL_ARG_NONNULL is copied here. */ + #ifdef __cplusplus extern "C" { @@ -74,7 +76,7 @@ #if @GNULIB_FREXP@ # if @REPLACE_FREXP@ # define frexp rpl_frexp -extern double frexp (double x, int *expptr); +extern double frexp (double x, int *expptr) _GL_ARG_NONNULL ((2)); # endif #elif defined GNULIB_POSIXCHECK # undef frexp @@ -211,7 +213,7 @@ # define frexpl rpl_frexpl #endif #if (@GNULIB_FREXPL@ && @REPLACE_FREXPL@) || !@HAVE_DECL_FREXPL@ -extern long double frexpl (long double x, int *expptr); +extern long double frexpl (long double x, int *expptr) _GL_ARG_NONNULL ((2)); #endif #if !@GNULIB_FREXPL@ && defined GNULIB_POSIXCHECK # undef frexpl
--- a/lib/netdb.in.h +++ b/lib/netdb.in.h @@ -1,5 +1,5 @@ /* Provide a netdb.h header file for systems lacking it (read: MinGW). - Copyright (C) 2008 Free Software Foundation, Inc. + Copyright (C) 2008-2009 Free Software Foundation, Inc. Written by Simon Josefsson. This program is free software; you can redistribute it and/or modify @@ -39,6 +39,8 @@ /* Get netdb.h definitions such as struct hostent for MinGW. */ #include <sys/socket.h> +/* The definition of _GL_ARG_NONNULL is copied here. */ + /* Declarations for a platform that lacks <netdb.h>, or where it is incomplete. */ @@ -141,14 +143,15 @@ extern int getaddrinfo (const char *restrict nodename, const char *restrict servname, const struct addrinfo *restrict hints, - struct addrinfo **restrict res); + struct addrinfo **restrict res) + _GL_ARG_NONNULL ((4)); # endif # if !@HAVE_DECL_FREEADDRINFO@ /* Free `addrinfo' structure AI including associated storage. For more details, see the POSIX:2001 specification <http://www.opengroup.org/susv3xsh/getaddrinfo.html>. */ -extern void freeaddrinfo (struct addrinfo *ai); +extern void freeaddrinfo (struct addrinfo *ai) _GL_ARG_NONNULL ((1)); # endif # if !@HAVE_DECL_GAI_STRERROR@ @@ -165,7 +168,8 @@ extern int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen, char *restrict node, socklen_t nodelen, char *restrict service, socklen_t servicelen, - int flags); + int flags) + _GL_ARG_NONNULL ((1)); # endif /* Possible flags for getnameinfo. */
--- a/lib/random_r.c +++ b/lib/random_r.c @@ -1,5 +1,5 @@ /* - Copyright (C) 1995, 2005, 2008 Free Software Foundation, Inc. + Copyright (C) 1995, 2005, 2008-2009 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -52,6 +52,11 @@ #include <config.h> +/* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc + optimizes away the buf == NULL, arg_state == NULL, result == NULL tests + below. */ +#define _GL_ARG_NONNULL(params) + #include <errno.h> #include <limits.h> #include <stddef.h>
--- a/lib/search.in.h +++ b/lib/search.in.h @@ -1,6 +1,6 @@ /* A GNU-like <search.h>. - Copyright (C) 2007-2008 Free Software Foundation, Inc. + Copyright (C) 2007-2009 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -31,6 +31,8 @@ /* The definition of GL_LINK_WARNING is copied here. */ +/* The definition of _GL_ARG_NONNULL is copied here. */ + #ifdef __cplusplus extern "C" { @@ -65,18 +67,21 @@ If one is found, it is returned. Otherwise, a new element equal to KEY is inserted in the tree and is returned. */ extern void * tsearch (const void *key, void **vrootp, - int (*compar) (const void *, const void *)); + int (*compar) (const void *, const void *)) + _GL_ARG_NONNULL ((1, 2, 3)); /* Searches an element in the tree *VROOTP that compares equal to KEY. If one is found, it is returned. Otherwise, NULL is returned. */ extern void * tfind (const void *key, void *const *vrootp, - int (*compar) (const void *, const void *)); + int (*compar) (const void *, const void *)) + _GL_ARG_NONNULL ((1, 2, 3)); /* Searches an element in the tree *VROOTP that compares equal to KEY. If one is found, it is removed from the tree, and its parent node is returned. Otherwise, NULL is returned. */ extern void * tdelete (const void *key, void **vrootp, - int (*compar) (const void *, const void *)); + int (*compar) (const void *, const void *)) + _GL_ARG_NONNULL ((1, 2, 3)); /* Perform a depth-first, left-to-right traversal of the tree VROOT. The ACTION function is called: @@ -90,7 +95,8 @@ 2. an indicator which visit of the node this is, 3. the level of the node in the tree (0 for the root). */ extern void twalk (const void *vroot, - void (*action) (const void *, VISIT, int)); + void (*action) (const void *, VISIT, int)) + _GL_ARG_NONNULL ((2)); # endif #elif defined GNULIB_POSIXCHECK
--- a/lib/setenv.c +++ b/lib/setenv.c @@ -17,6 +17,11 @@ #if !_LIBC # include <config.h> #endif + +/* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc + optimizes away the name == NULL test below. */ +#define _GL_ARG_NONNULL(params) + #include <alloca.h> /* Specification. */
--- a/lib/signal.in.h +++ b/lib/signal.in.h @@ -37,6 +37,8 @@ /* The definition of GL_LINK_WARNING is copied here. */ +/* The definition of _GL_ARG_NONNULL is copied here. */ + /* Define pid_t, uid_t. Also, mingw defines sigset_t not in <signal.h>, but in <sys/types.h>. */ #include <sys/types.h> @@ -82,22 +84,22 @@ # endif /* Test whether a given signal is contained in a signal set. */ -extern int sigismember (const sigset_t *set, int sig); +extern int sigismember (const sigset_t *set, int sig) _GL_ARG_NONNULL ((1)); /* Initialize a signal set to the empty set. */ -extern int sigemptyset (sigset_t *set); +extern int sigemptyset (sigset_t *set) _GL_ARG_NONNULL ((1)); /* Add a signal to a signal set. */ -extern int sigaddset (sigset_t *set, int sig); +extern int sigaddset (sigset_t *set, int sig) _GL_ARG_NONNULL ((1)); /* Remove a signal from a signal set. */ -extern int sigdelset (sigset_t *set, int sig); +extern int sigdelset (sigset_t *set, int sig) _GL_ARG_NONNULL ((1)); /* Fill a signal set with all possible signals. */ -extern int sigfillset (sigset_t *set); +extern int sigfillset (sigset_t *set) _GL_ARG_NONNULL ((1)); /* Return the set of those blocked signals that are pending. */ -extern int sigpending (sigset_t *set); +extern int sigpending (sigset_t *set) _GL_ARG_NONNULL ((1)); /* If OLD_SET is not NULL, put the current set of blocked signals in *OLD_SET. Then, if SET is not NULL, affect the current set of blocked signals by
--- a/lib/spawn.in.h +++ b/lib/spawn.in.h @@ -1,5 +1,5 @@ /* Definitions for POSIX spawn interface. - Copyright (C) 2000, 2003, 2004, 2008 Free Software Foundation, Inc. + Copyright (C) 2000, 2003, 2004, 2008-2009 Free Software Foundation, Inc. This file is part of the GNU C Library. This program is free software: you can redistribute it and/or modify @@ -67,6 +67,8 @@ /* The definition of GL_LINK_WARNING is copied here. */ +/* The definition of _GL_ARG_NONNULL is copied here. */ + /* Data structure to contain attributes for thread creation. */ #if @REPLACE_POSIX_SPAWN@ @@ -147,7 +149,8 @@ const posix_spawn_file_actions_t *_Restrict_ __file_actions, const posix_spawnattr_t *_Restrict_ __attrp, char *const argv[_Restrict_arr_], - char *const envp[_Restrict_arr_]); + char *const envp[_Restrict_arr_]) + _GL_ARG_NONNULL ((2, 5, 6)); # endif #endif @@ -163,7 +166,8 @@ extern int posix_spawnp (pid_t *__pid, const char *__file, const posix_spawn_file_actions_t *__file_actions, const posix_spawnattr_t *__attrp, - char *const argv[], char *const envp[]); + char *const argv[], char *const envp[]) + _GL_ARG_NONNULL ((2, 5, 6)); # endif #endif @@ -174,7 +178,8 @@ # define posix_spawnattr_init rpl_posix_spawnattr_init # endif # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@ -extern int posix_spawnattr_init (posix_spawnattr_t *__attr) __THROW; +extern int posix_spawnattr_init (posix_spawnattr_t *__attr) + __THROW _GL_ARG_NONNULL ((1)); # endif #endif @@ -184,7 +189,8 @@ # define posix_spawnattr_destroy rpl_posix_spawnattr_destroy # endif # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@ -extern int posix_spawnattr_destroy (posix_spawnattr_t *__attr) __THROW; +extern int posix_spawnattr_destroy (posix_spawnattr_t *__attr) + __THROW _GL_ARG_NONNULL ((1)); # endif #endif @@ -197,7 +203,7 @@ # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@ extern int posix_spawnattr_getsigdefault (const posix_spawnattr_t *_Restrict_ __attr, sigset_t *_Restrict_ __sigdefault) - __THROW; + __THROW _GL_ARG_NONNULL ((1, 2)); # endif #endif @@ -209,7 +215,7 @@ # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@ extern int posix_spawnattr_setsigdefault (posix_spawnattr_t *_Restrict_ __attr, const sigset_t *_Restrict_ __sigdefault) - __THROW; + __THROW _GL_ARG_NONNULL ((1, 2)); # endif #endif @@ -220,7 +226,8 @@ # endif # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@ extern int posix_spawnattr_getsigmask (const posix_spawnattr_t *_Restrict_ __attr, - sigset_t *_Restrict_ __sigmask) __THROW; + sigset_t *_Restrict_ __sigmask) + __THROW _GL_ARG_NONNULL ((1, 2)); # endif #endif @@ -232,7 +239,7 @@ # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@ extern int posix_spawnattr_setsigmask (posix_spawnattr_t *_Restrict_ __attr, const sigset_t *_Restrict_ __sigmask) - __THROW; + __THROW _GL_ARG_NONNULL ((1, 2)); # endif #endif @@ -243,7 +250,8 @@ # endif # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@ extern int posix_spawnattr_getflags (const posix_spawnattr_t *_Restrict_ __attr, - short int *_Restrict_ __flags) __THROW; + short int *_Restrict_ __flags) + __THROW _GL_ARG_NONNULL ((1, 2)); # endif #endif @@ -254,7 +262,8 @@ # endif # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@ extern int posix_spawnattr_setflags (posix_spawnattr_t *__attr, - short int __flags) __THROW; + short int __flags) + __THROW _GL_ARG_NONNULL ((1)); # endif #endif @@ -266,7 +275,7 @@ # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@ extern int posix_spawnattr_getpgroup (const posix_spawnattr_t *_Restrict_ __attr, pid_t *_Restrict_ __pgroup) - __THROW; + __THROW _GL_ARG_NONNULL ((1, 2)); # endif #endif @@ -277,7 +286,8 @@ # endif # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@ extern int posix_spawnattr_setpgroup (posix_spawnattr_t *__attr, - pid_t __pgroup) __THROW; + pid_t __pgroup) + __THROW _GL_ARG_NONNULL ((1)); # endif #endif @@ -289,7 +299,7 @@ # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@ extern int posix_spawnattr_getschedpolicy (const posix_spawnattr_t *_Restrict_ __attr, int *_Restrict_ __schedpolicy) - __THROW; + __THROW _GL_ARG_NONNULL ((1, 2)); # endif #endif @@ -300,7 +310,8 @@ # endif # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@ extern int posix_spawnattr_setschedpolicy (posix_spawnattr_t *__attr, - int __schedpolicy) __THROW; + int __schedpolicy) + __THROW _GL_ARG_NONNULL ((1)); # endif #endif @@ -311,7 +322,8 @@ # endif # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@ extern int posix_spawnattr_getschedparam (const posix_spawnattr_t *_Restrict_ __attr, - struct sched_param *_Restrict_ __schedparam) __THROW; + struct sched_param *_Restrict_ __schedparam) + __THROW _GL_ARG_NONNULL ((1, 2)); # endif #endif @@ -322,7 +334,8 @@ # endif # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@ extern int posix_spawnattr_setschedparam (posix_spawnattr_t *_Restrict_ __attr, - const struct sched_param *_Restrict_ __schedparam) __THROW; + const struct sched_param *_Restrict_ __schedparam) + __THROW _GL_ARG_NONNULL ((1, 2)); # endif #endif @@ -333,7 +346,8 @@ # define posix_spawn_file_actions_init rpl_posix_spawn_file_actions_init # endif # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@ -extern int posix_spawn_file_actions_init (posix_spawn_file_actions_t *__file_actions) __THROW; +extern int posix_spawn_file_actions_init (posix_spawn_file_actions_t *__file_actions) + __THROW _GL_ARG_NONNULL ((1)); # endif #endif @@ -343,7 +357,8 @@ # define posix_spawn_file_actions_destroy rpl_posix_spawn_file_actions_destroy # endif # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@ -extern int posix_spawn_file_actions_destroy (posix_spawn_file_actions_t *__file_actions) __THROW; +extern int posix_spawn_file_actions_destroy (posix_spawn_file_actions_t *__file_actions) + __THROW _GL_ARG_NONNULL ((1)); # endif #endif @@ -358,7 +373,7 @@ int __fd, const char *_Restrict_ __path, int __oflag, mode_t __mode) - __THROW; + __THROW _GL_ARG_NONNULL ((1, 3)); # endif #endif @@ -371,7 +386,7 @@ # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@ extern int posix_spawn_file_actions_addclose (posix_spawn_file_actions_t *__file_actions, int __fd) - __THROW; + __THROW _GL_ARG_NONNULL ((1)); # endif #endif @@ -383,7 +398,8 @@ # endif # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@ extern int posix_spawn_file_actions_adddup2 (posix_spawn_file_actions_t *__file_actions, - int __fd, int __newfd) __THROW; + int __fd, int __newfd) + __THROW _GL_ARG_NONNULL ((1)); # endif #endif
--- a/lib/stdio.in.h +++ b/lib/stdio.in.h @@ -63,6 +63,8 @@ /* The definition of GL_LINK_WARNING is copied here. */ +/* The definition of _GL_ARG_NONNULL is copied here. */ + #ifdef __cplusplus extern "C" { @@ -74,7 +76,7 @@ # endif # if @REPLACE_DPRINTF@ || !@HAVE_DPRINTF@ extern int dprintf (int fd, const char *format, ...) - __attribute__ ((__format__ (__printf__, 2, 3))); + __attribute__ ((__format__ (__printf__, 2, 3))) _GL_ARG_NONNULL ((2)); # endif #elif defined GNULIB_POSIXCHECK # undef dprintf @@ -88,7 +90,7 @@ # if @REPLACE_FCLOSE@ # define fclose rpl_fclose /* Close STREAM and its underlying file descriptor. */ -extern int fclose (FILE *stream); +extern int fclose (FILE *stream) _GL_ARG_NONNULL ((1)); # endif #elif defined GNULIB_POSIXCHECK # undef fclose @@ -123,7 +125,8 @@ # if @REPLACE_FOPEN@ # undef fopen # define fopen rpl_fopen -extern FILE * fopen (const char *filename, const char *mode); +extern FILE * fopen (const char *filename, const char *mode) + _GL_ARG_NONNULL ((1, 2)); # endif #elif defined GNULIB_POSIXCHECK # undef fopen @@ -137,12 +140,14 @@ # if @REPLACE_FPRINTF@ # define fprintf rpl_fprintf extern int fprintf (FILE *fp, const char *format, ...) - __attribute__ ((__format__ (__printf__, 2, 3))); + __attribute__ ((__format__ (__printf__, 2, 3))) + _GL_ARG_NONNULL ((1, 2)); # endif #elif @GNULIB_FPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@ # define fprintf rpl_fprintf extern int fprintf (FILE *fp, const char *format, ...) - __attribute__ ((__format__ (__printf__, 2, 3))); + __attribute__ ((__format__ (__printf__, 2, 3))) + _GL_ARG_NONNULL ((1, 2)); #elif defined GNULIB_POSIXCHECK # undef fprintf # define fprintf \ @@ -163,7 +168,7 @@ was before the write calls. When discarding pending input, the file position is advanced to match the end of the previously read input. Return 0 if successful. Upon error, return -1 and set errno. */ - extern int fpurge (FILE *gl_stream); + extern int fpurge (FILE *gl_stream) _GL_ARG_NONNULL ((1)); # endif #elif defined GNULIB_POSIXCHECK # undef fpurge @@ -176,20 +181,21 @@ #if @GNULIB_FPUTC@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@ # undef fputc # define fputc rpl_fputc -extern int fputc (int c, FILE *stream); +extern int fputc (int c, FILE *stream) _GL_ARG_NONNULL ((2)); #endif #if @GNULIB_FPUTS@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@ # undef fputs # define fputs rpl_fputs -extern int fputs (const char *string, FILE *stream); +extern int fputs (const char *string, FILE *stream) _GL_ARG_NONNULL ((1, 2)); #endif #if @GNULIB_FREOPEN@ # if @REPLACE_FREOPEN@ # undef freopen # define freopen rpl_freopen -extern FILE * freopen (const char *filename, const char *mode, FILE *stream); +extern FILE * freopen (const char *filename, const char *mode, FILE *stream) + _GL_ARG_NONNULL ((2, 3)); # endif #elif defined GNULIB_POSIXCHECK # undef freopen @@ -200,7 +206,7 @@ #endif #if @GNULIB_FSEEK@ && @REPLACE_FSEEK@ -extern int rpl_fseek (FILE *fp, long offset, int whence); +extern int rpl_fseek (FILE *fp, long offset, int whence) _GL_ARG_NONNULL ((1)); # undef fseek # if defined GNULIB_POSIXCHECK # define fseek(f,o,w) \ @@ -226,7 +232,7 @@ /* Provide fseek, fseeko functions that are aware of a preceding fflush(), and which detect pipes. */ # define fseeko rpl_fseeko -extern int fseeko (FILE *fp, off_t offset, int whence); +extern int fseeko (FILE *fp, off_t offset, int whence) _GL_ARG_NONNULL ((1)); # if !@GNULIB_FSEEK@ # undef fseek # define fseek(f,o,w) \ @@ -245,7 +251,7 @@ #endif #if @GNULIB_FTELL@ && @REPLACE_FTELL@ -extern long rpl_ftell (FILE *fp); +extern long rpl_ftell (FILE *fp) _GL_ARG_NONNULL ((1)); # undef ftell # if GNULIB_POSIXCHECK # define ftell(f) \ @@ -269,7 +275,7 @@ #if @GNULIB_FTELLO@ # if @REPLACE_FTELLO@ # define ftello rpl_ftello -extern off_t ftello (FILE *fp); +extern off_t ftello (FILE *fp) _GL_ARG_NONNULL ((1)); # if !@GNULIB_FTELL@ # undef ftell # define ftell(f) \ @@ -290,7 +296,8 @@ #if @GNULIB_FWRITE@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@ # undef fwrite # define fwrite rpl_fwrite -extern size_t fwrite (const void *ptr, size_t s, size_t n, FILE *stream); +extern size_t fwrite (const void *ptr, size_t s, size_t n, FILE *stream) + _GL_ARG_NONNULL ((1, 4)); #endif #if @GNULIB_GETDELIM@ @@ -302,7 +309,8 @@ Return the number of bytes read and stored at *LINEPTR (not including the NUL terminator), or -1 on error or EOF. */ extern ssize_t getdelim (char **lineptr, size_t *linesize, int delimiter, - FILE *stream); + FILE *stream) + _GL_ARG_NONNULL ((1, 2, 4)); # endif #elif defined GNULIB_POSIXCHECK # undef getdelim @@ -324,7 +332,8 @@ bytes of space. It is realloc'd as necessary. Return the number of bytes read and stored at *LINEPTR (not including the NUL terminator), or -1 on error or EOF. */ -extern ssize_t getline (char **lineptr, size_t *linesize, FILE *stream); +extern ssize_t getline (char **lineptr, size_t *linesize, FILE *stream) + _GL_ARG_NONNULL ((1, 2, 3)); # endif #elif defined GNULIB_POSIXCHECK # undef getline @@ -347,10 +356,10 @@ memory allocation error, call obstack_alloc_failed_handler. Upon other error, return -1. */ extern int obstack_printf (struct obstack *obs, const char *format, ...) - __attribute__ ((__format__ (__printf__, 2, 3))); + __attribute__ ((__format__ (__printf__, 2, 3))) _GL_ARG_NONNULL ((1, 2)); extern int obstack_vprintf (struct obstack *obs, const char *format, va_list args) - __attribute__ ((__format__ (__printf__, 2, 0))); + __attribute__ ((__format__ (__printf__, 2, 0))) _GL_ARG_NONNULL ((1, 2)); # endif #endif @@ -374,7 +383,8 @@ # if @REPLACE_POPEN@ # undef popen # define popen rpl_popen -extern FILE *popen (const char *cmd, const char *mode); +extern FILE *popen (const char *cmd, const char *mode) + _GL_ARG_NONNULL ((1, 2)); # endif #elif defined GNULIB_POSIXCHECK # undef popen @@ -389,13 +399,13 @@ /* Don't break __attribute__((format(printf,M,N))). */ # define printf __printf__ extern int printf (const char *format, ...) - __attribute__ ((__format__ (__printf__, 1, 2))); + __attribute__ ((__format__ (__printf__, 1, 2))) _GL_ARG_NONNULL ((1)); # endif #elif @GNULIB_PRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@ /* Don't break __attribute__((format(printf,M,N))). */ # define printf __printf__ extern int printf (const char *format, ...) - __attribute__ ((__format__ (__printf__, 1, 2))); + __attribute__ ((__format__ (__printf__, 1, 2))) _GL_ARG_NONNULL ((1)); #elif defined GNULIB_POSIXCHECK # undef printf # define printf \ @@ -415,7 +425,7 @@ #if @GNULIB_PUTC@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@ # undef putc # define putc rpl_fputc -extern int putc (int c, FILE *stream); +extern int putc (int c, FILE *stream) _GL_ARG_NONNULL ((2)); #endif #if @GNULIB_PUTCHAR@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@ @@ -427,14 +437,14 @@ #if @GNULIB_PUTS@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@ # undef puts # define puts rpl_puts -extern int puts (const char *string); +extern int puts (const char *string) _GL_ARG_NONNULL ((1)); #endif #if @GNULIB_REMOVE@ # if @REPLACE_REMOVE@ # undef remove # define remove rpl_remove -extern int remove (const char *name); +extern int remove (const char *name) _GL_ARG_NONNULL ((1)); # endif #elif defined GNULIB_POSIXCHECK # undef remove @@ -448,7 +458,8 @@ # if @REPLACE_RENAME@ # undef rename # define rename rpl_rename -extern int rename (const char *old_filename, const char *new_filename); +extern int rename (const char *old_filename, const char *new_filename) + _GL_ARG_NONNULL ((1, 2)); # endif #elif defined GNULIB_POSIXCHECK # undef rename @@ -464,7 +475,8 @@ # define renameat rpl_renameat # endif # if !@HAVE_RENAMEAT@ || @REPLACE_RENAMEAT@ -extern int renameat (int fd1, char const *file1, int fd2, char const *file2); +extern int renameat (int fd1, char const *file1, int fd2, char const *file2) + _GL_ARG_NONNULL ((2, 4)); # endif #elif defined GNULIB_POSIXCHECK # undef renameat @@ -480,7 +492,8 @@ # endif # if @REPLACE_SNPRINTF@ || !@HAVE_DECL_SNPRINTF@ extern int snprintf (char *str, size_t size, const char *format, ...) - __attribute__ ((__format__ (__printf__, 3, 4))); + __attribute__ ((__format__ (__printf__, 3, 4))) + _GL_ARG_NONNULL ((3)); # endif #elif defined GNULIB_POSIXCHECK # undef snprintf @@ -494,7 +507,8 @@ # if @REPLACE_SPRINTF@ # define sprintf rpl_sprintf extern int sprintf (char *str, const char *format, ...) - __attribute__ ((__format__ (__printf__, 2, 3))); + __attribute__ ((__format__ (__printf__, 2, 3))) + _GL_ARG_NONNULL ((1, 2)); # endif #elif defined GNULIB_POSIXCHECK # undef sprintf @@ -516,9 +530,9 @@ *RESULT and return the number of resulting bytes, excluding the trailing NUL. Upon memory allocation error, or some other error, return -1. */ extern int asprintf (char **result, const char *format, ...) - __attribute__ ((__format__ (__printf__, 2, 3))); + __attribute__ ((__format__ (__printf__, 2, 3))) _GL_ARG_NONNULL ((1, 2)); extern int vasprintf (char **result, const char *format, va_list args) - __attribute__ ((__format__ (__printf__, 2, 0))); + __attribute__ ((__format__ (__printf__, 2, 0))) _GL_ARG_NONNULL ((1, 2)); # endif #endif @@ -528,7 +542,7 @@ # endif # if @REPLACE_VDPRINTF@ || !@HAVE_VDPRINTF@ extern int vdprintf (int fd, const char *format, va_list args) - __attribute__ ((__format__ (__printf__, 2, 0))); + __attribute__ ((__format__ (__printf__, 2, 0))) _GL_ARG_NONNULL ((2)); # endif #elif defined GNULIB_POSIXCHECK # undef vdprintf @@ -542,12 +556,14 @@ # if @REPLACE_VFPRINTF@ # define vfprintf rpl_vfprintf extern int vfprintf (FILE *fp, const char *format, va_list args) - __attribute__ ((__format__ (__printf__, 2, 0))); + __attribute__ ((__format__ (__printf__, 2, 0))) + _GL_ARG_NONNULL ((1, 2)); # endif #elif @GNULIB_VFPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@ # define vfprintf rpl_vfprintf extern int vfprintf (FILE *fp, const char *format, va_list args) - __attribute__ ((__format__ (__printf__, 2, 0))); + __attribute__ ((__format__ (__printf__, 2, 0))) + _GL_ARG_NONNULL ((1, 2)); #elif defined GNULIB_POSIXCHECK # undef vfprintf # define vfprintf(s,f,a) \ @@ -561,12 +577,12 @@ # if @REPLACE_VPRINTF@ # define vprintf rpl_vprintf extern int vprintf (const char *format, va_list args) - __attribute__ ((__format__ (__printf__, 1, 0))); + __attribute__ ((__format__ (__printf__, 1, 0))) _GL_ARG_NONNULL ((1)); # endif #elif @GNULIB_VPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@ # define vprintf rpl_vprintf extern int vprintf (const char *format, va_list args) - __attribute__ ((__format__ (__printf__, 1, 0))); + __attribute__ ((__format__ (__printf__, 1, 0))) _GL_ARG_NONNULL ((1)); #elif defined GNULIB_POSIXCHECK # undef vprintf # define vprintf(f,a) \ @@ -582,7 +598,8 @@ # endif # if @REPLACE_VSNPRINTF@ || !@HAVE_DECL_VSNPRINTF@ extern int vsnprintf (char *str, size_t size, const char *format, va_list args) - __attribute__ ((__format__ (__printf__, 3, 0))); + __attribute__ ((__format__ (__printf__, 3, 0))) + _GL_ARG_NONNULL ((3)); # endif #elif defined GNULIB_POSIXCHECK # undef vsnprintf @@ -596,7 +613,8 @@ # if @REPLACE_VSPRINTF@ # define vsprintf rpl_vsprintf extern int vsprintf (char *str, const char *format, va_list args) - __attribute__ ((__format__ (__printf__, 2, 0))); + __attribute__ ((__format__ (__printf__, 2, 0))) + _GL_ARG_NONNULL ((1, 2)); # endif #elif defined GNULIB_POSIXCHECK # undef vsprintf
--- a/lib/stdlib.in.h +++ b/lib/stdlib.in.h @@ -68,6 +68,8 @@ /* The definition of GL_LINK_WARNING is copied here. */ +/* The definition of _GL_ARG_NONNULL is copied here. */ + /* Some systems do not define EXIT_*, despite otherwise supporting C89. */ #ifndef EXIT_SUCCESS @@ -91,7 +93,7 @@ # if !@HAVE_ATOLL@ /* Parse a signed decimal integer. Returns the value of the integer. Errors are not detected. */ -extern long long atoll (const char *string); +extern long long atoll (const char *string) _GL_ARG_NONNULL ((1)); # endif #elif defined GNULIB_POSIXCHECK # undef atoll @@ -120,7 +122,7 @@ # define canonicalize_file_name rpl_canonicalize_file_name # endif # if !@HAVE_CANONICALIZE_FILE_NAME@ || @REPLACE_CANONICALIZE_FILE_NAME@ -extern char *canonicalize_file_name (const char *name); +extern char *canonicalize_file_name (const char *name) _GL_ARG_NONNULL ((1)); # endif #elif defined GNULIB_POSIXCHECK # undef canonicalize_file_name @@ -136,7 +138,7 @@ The three numbers are the load average of the last 1 minute, the last 5 minutes, and the last 15 minutes, respectively. LOADAVG is an array of NELEM numbers. */ -extern int getloadavg (double loadavg[], int nelem); +extern int getloadavg (double loadavg[], int nelem) _GL_ARG_NONNULL ((1)); # endif #elif defined GNULIB_POSIXCHECK # undef getloadavg @@ -159,7 +161,8 @@ For more details see the POSIX:2001 specification. http://www.opengroup.org/susv3xsh/getsubopt.html */ # if !@HAVE_GETSUBOPT@ -extern int getsubopt (char **optionp, char *const *tokens, char **valuep); +extern int getsubopt (char **optionp, char *const *tokens, char **valuep) + _GL_ARG_NONNULL ((1, 2, 3)); # endif #elif defined GNULIB_POSIXCHECK # undef getsubopt @@ -190,7 +193,7 @@ they are replaced with a string that makes the directory name unique. Returns TEMPLATE, or a null pointer if it cannot get a unique name. The directory is created mode 700. */ -extern char * mkdtemp (char * /*template*/); +extern char * mkdtemp (char * /*template*/) _GL_ARG_NONNULL ((1)); # endif #elif defined GNULIB_POSIXCHECK # undef mkdtemp @@ -214,7 +217,7 @@ implementation. Returns the open file descriptor if successful, otherwise -1 and errno set. */ -extern int mkostemp (char * /*template*/, int /*flags*/); +extern int mkostemp (char * /*template*/, int /*flags*/) _GL_ARG_NONNULL ((1)); # endif #elif defined GNULIB_POSIXCHECK # undef mkostemp @@ -239,7 +242,8 @@ implementation. Returns the open file descriptor if successful, otherwise -1 and errno set. */ -extern int mkostemps (char * /*template*/, int /*suffixlen*/, int /*flags*/); +extern int mkostemps (char * /*template*/, int /*suffixlen*/, int /*flags*/) + _GL_ARG_NONNULL ((1)); # endif #elif defined GNULIB_POSIXCHECK # undef mkostemps @@ -261,7 +265,7 @@ Returns the open file descriptor if successful, otherwise -1 and errno set. */ # define mkstemp rpl_mkstemp -extern int mkstemp (char * /*template*/); +extern int mkstemp (char * /*template*/) _GL_ARG_NONNULL ((1)); # else /* On MacOS X 10.3, only <unistd.h> declares mkstemp. */ # include <unistd.h> @@ -286,7 +290,8 @@ implementation. Returns the open file descriptor if successful, otherwise -1 and errno set. */ -extern int mkstemps (char * /*template*/, int /*suffixlen*/); +extern int mkstemps (char * /*template*/, int /*suffixlen*/) + _GL_ARG_NONNULL ((1)); # endif #elif defined GNULIB_POSIXCHECK # undef mkstemps @@ -300,7 +305,7 @@ # if @REPLACE_PUTENV@ # undef putenv # define putenv rpl_putenv -extern int putenv (char *string); +extern int putenv (char *string) _GL_ARG_NONNULL ((1)); # endif #endif @@ -311,11 +316,15 @@ # define RAND_MAX 2147483647 # endif -int srandom_r (unsigned int seed, struct random_data *rand_state); +int srandom_r (unsigned int seed, struct random_data *rand_state) + _GL_ARG_NONNULL ((2)); int initstate_r (unsigned int seed, char *buf, size_t buf_size, - struct random_data *rand_state); -int setstate_r (char *arg_state, struct random_data *rand_state); -int random_r (struct random_data *buf, int32_t *result); + struct random_data *rand_state) + _GL_ARG_NONNULL ((2, 4)); +int setstate_r (char *arg_state, struct random_data *rand_state) + _GL_ARG_NONNULL ((1, 2)); +int random_r (struct random_data *buf, int32_t *result) + _GL_ARG_NONNULL ((1, 2)); # endif #elif defined GNULIB_POSIXCHECK # undef random_r @@ -359,7 +368,7 @@ # define realpath rpl_realpath # endif # if !@HAVE_REALPATH@ || @REPLACE_REALPATH@ -extern char *realpath (const char *name, char *resolved); +extern char *realpath (const char *name, char *resolved) _GL_ARG_NONNULL ((1)); # endif #elif defined GNULIB_POSIXCHECK # undef realpath @@ -373,7 +382,7 @@ # if !@HAVE_RPMATCH@ /* Test a user response to a question. Return 1 if it is affirmative, 0 if it is negative, or -1 if not clear. */ -extern int rpmatch (const char *response); +extern int rpmatch (const char *response) _GL_ARG_NONNULL ((1)); # endif #elif defined GNULIB_POSIXCHECK # undef rpmatch @@ -391,7 +400,8 @@ # if !@HAVE_SETENV@ || @REPLACE_SETENV@ /* Set NAME to VALUE in the environment. If REPLACE is nonzero, overwrite an existing value. */ -extern int setenv (const char *name, const char *value, int replace); +extern int setenv (const char *name, const char *value, int replace) + _GL_ARG_NONNULL ((1)); # endif #elif defined GNULIB_POSIXCHECK # undef setenv @@ -407,7 +417,7 @@ # endif # if !@HAVE_STRTOD@ || @REPLACE_STRTOD@ /* Parse a double from STRING, updating ENDP if appropriate. */ -extern double strtod (const char *str, char **endp); +extern double strtod (const char *str, char **endp) _GL_ARG_NONNULL ((1)); # endif #elif defined GNULIB_POSIXCHECK # undef strtod @@ -427,7 +437,8 @@ stored in *ENDPTR. Upon overflow, the return value is LLONG_MAX or LLONG_MIN, and errno is set to ERANGE. */ -extern long long strtoll (const char *string, char **endptr, int base); +extern long long strtoll (const char *string, char **endptr, int base) + _GL_ARG_NONNULL ((1)); # endif #elif defined GNULIB_POSIXCHECK # undef strtoll @@ -447,7 +458,8 @@ stored in *ENDPTR. Upon overflow, the return value is ULLONG_MAX, and errno is set to ERANGE. */ -extern unsigned long long strtoull (const char *string, char **endptr, int base); +extern unsigned long long strtoull (const char *string, char **endptr, int base) + _GL_ARG_NONNULL ((1)); # endif #elif defined GNULIB_POSIXCHECK # undef strtoull @@ -464,7 +476,7 @@ # endif # if !@HAVE_UNSETENV@ || @REPLACE_UNSETENV@ /* Remove the variable NAME from the environment. */ -extern int unsetenv (const char *name); +extern int unsetenv (const char *name) _GL_ARG_NONNULL ((1)); # endif #elif defined GNULIB_POSIXCHECK # undef unsetenv
--- a/lib/string.in.h +++ b/lib/string.in.h @@ -45,6 +45,8 @@ /* The definition of GL_LINK_WARNING is copied here. */ +/* The definition of _GL_ARG_NONNULL is copied here. */ + #ifdef __cplusplus extern "C" { @@ -56,7 +58,7 @@ # if @REPLACE_MEMCHR@ # define memchr rpl_memchr extern void *memchr (void const *__s, int __c, size_t __n) - __attribute__ ((__pure__)); + __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1)); # endif #elif defined GNULIB_POSIXCHECK # undef memchr @@ -74,7 +76,7 @@ # if ! @HAVE_DECL_MEMMEM@ || @REPLACE_MEMMEM@ extern void *memmem (void const *__haystack, size_t __haystack_len, void const *__needle, size_t __needle_len) - __attribute__ ((__pure__)); + __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1, 3)); # endif #elif defined GNULIB_POSIXCHECK # undef memmem @@ -90,7 +92,8 @@ #if @GNULIB_MEMPCPY@ # if ! @HAVE_MEMPCPY@ extern void *mempcpy (void *restrict __dest, void const *restrict __src, - size_t __n); + size_t __n) + _GL_ARG_NONNULL ((1, 2)); # endif #elif defined GNULIB_POSIXCHECK # undef mempcpy @@ -104,7 +107,7 @@ #if @GNULIB_MEMRCHR@ # if ! @HAVE_DECL_MEMRCHR@ extern void *memrchr (void const *, int, size_t) - __attribute__ ((__pure__)); + __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1)); # endif #elif defined GNULIB_POSIXCHECK # undef memrchr @@ -120,7 +123,7 @@ #if @GNULIB_RAWMEMCHR@ # if ! @HAVE_RAWMEMCHR@ extern void *rawmemchr (void const *__s, int __c_in) - __attribute__ ((__pure__)); + __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1)); # endif #elif defined GNULIB_POSIXCHECK # undef rawmemchr @@ -133,7 +136,8 @@ /* Copy SRC to DST, returning the address of the terminating '\0' in DST. */ #if @GNULIB_STPCPY@ # if ! @HAVE_STPCPY@ -extern char *stpcpy (char *restrict __dst, char const *restrict __src); +extern char *stpcpy (char *restrict __dst, char const *restrict __src) + _GL_ARG_NONNULL ((1, 2)); # endif #elif defined GNULIB_POSIXCHECK # undef stpcpy @@ -149,7 +153,8 @@ # if ! @HAVE_STPNCPY@ # define stpncpy gnu_stpncpy extern char *stpncpy (char *restrict __dst, char const *restrict __src, - size_t __n); + size_t __n) + _GL_ARG_NONNULL ((1, 2)); # endif #elif defined GNULIB_POSIXCHECK # undef stpncpy @@ -174,7 +179,7 @@ #if @GNULIB_STRCHRNUL@ # if ! @HAVE_STRCHRNUL@ extern char *strchrnul (char const *__s, int __c_in) - __attribute__ ((__pure__)); + __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1)); # endif #elif defined GNULIB_POSIXCHECK # undef strchrnul @@ -191,7 +196,7 @@ # define strdup rpl_strdup # endif # if !(@HAVE_DECL_STRDUP@ || defined strdup) || @REPLACE_STRDUP@ -extern char *strdup (char const *__s); +extern char *strdup (char const *__s) _GL_ARG_NONNULL ((1)); # endif #elif defined GNULIB_POSIXCHECK # undef strdup @@ -208,7 +213,7 @@ # define strndup rpl_strndup # endif # if @REPLACE_STRNDUP@ || ! @HAVE_DECL_STRNDUP@ -extern char *strndup (char const *__string, size_t __n); +extern char *strndup (char const *__string, size_t __n) _GL_ARG_NONNULL ((1)); # endif #elif defined GNULIB_POSIXCHECK # undef strndup @@ -224,7 +229,7 @@ #if @GNULIB_STRNLEN@ # if ! @HAVE_DECL_STRNLEN@ extern size_t strnlen (char const *__string, size_t __maxlen) - __attribute__ ((__pure__)); + __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1)); # endif #elif defined GNULIB_POSIXCHECK # undef strnlen @@ -251,7 +256,7 @@ #if @GNULIB_STRPBRK@ # if ! @HAVE_STRPBRK@ extern char *strpbrk (char const *__s, char const *__accept) - __attribute__ ((__pure__)); + __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1, 2)); # endif # if defined GNULIB_POSIXCHECK /* strpbrk() assumes the second argument is a list of single-byte characters. @@ -313,7 +318,8 @@ See also strtok_r(). */ #if @GNULIB_STRSEP@ # if ! @HAVE_STRSEP@ -extern char *strsep (char **restrict __stringp, char const *restrict __delim); +extern char *strsep (char **restrict __stringp, char const *restrict __delim) + _GL_ARG_NONNULL ((1, 2)); # endif # if defined GNULIB_POSIXCHECK # undef strsep @@ -334,8 +340,8 @@ #if @GNULIB_STRSTR@ # if @REPLACE_STRSTR@ # define strstr rpl_strstr -char *strstr (const char *haystack, const char *needle) - __attribute__ ((__pure__)); +extern char *strstr (const char *haystack, const char *needle) + __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1, 2)); # endif #elif defined GNULIB_POSIXCHECK /* strstr() does not work with multibyte strings if the locale encoding is @@ -360,7 +366,7 @@ # endif # if ! @HAVE_STRCASESTR@ || @REPLACE_STRCASESTR@ extern char *strcasestr (const char *haystack, const char *needle) - __attribute__ ((__pure__)); + __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1, 2)); # endif #elif defined GNULIB_POSIXCHECK /* strcasestr() does not work with multibyte strings: @@ -407,7 +413,8 @@ # endif # if ! @HAVE_DECL_STRTOK_R@ || @REPLACE_STRTOK_R@ extern char *strtok_r (char *restrict s, char const *restrict delim, - char **restrict save_ptr); + char **restrict save_ptr) + _GL_ARG_NONNULL ((2, 3)); # endif # if defined GNULIB_POSIXCHECK # undef strtok_r @@ -432,13 +439,13 @@ #if @GNULIB_MBSLEN@ /* Return the number of multibyte characters in the character string STRING. This considers multibyte characters, unlike strlen, which counts bytes. */ -extern size_t mbslen (const char *string); +extern size_t mbslen (const char *string) _GL_ARG_NONNULL ((1)); #endif #if @GNULIB_MBSNLEN@ /* Return the number of multibyte characters in the character string starting at STRING and ending at STRING + LEN. */ -extern size_t mbsnlen (const char *string, size_t len); +extern size_t mbsnlen (const char *string, size_t len) _GL_ARG_NONNULL ((1)); #endif #if @GNULIB_MBSCHR@ @@ -447,7 +454,7 @@ Unlike strchr(), this function works correctly in multibyte locales with encodings such as GB18030. */ # define mbschr rpl_mbschr /* avoid collision with HP-UX function */ -extern char * mbschr (const char *string, int c); +extern char * mbschr (const char *string, int c) _GL_ARG_NONNULL ((1)); #endif #if @GNULIB_MBSRCHR@ @@ -456,7 +463,7 @@ Unlike strrchr(), this function works correctly in multibyte locales with encodings such as GB18030. */ # define mbsrchr rpl_mbsrchr /* avoid collision with HP-UX function */ -extern char * mbsrchr (const char *string, int c); +extern char * mbsrchr (const char *string, int c) _GL_ARG_NONNULL ((1)); #endif #if @GNULIB_MBSSTR@ @@ -464,7 +471,8 @@ string HAYSTACK. Return NULL if NEEDLE is not found in HAYSTACK. Unlike strstr(), this function works correctly in multibyte locales with encodings different from UTF-8. */ -extern char * mbsstr (const char *haystack, const char *needle); +extern char * mbsstr (const char *haystack, const char *needle) + _GL_ARG_NONNULL ((1, 2)); #endif #if @GNULIB_MBSCASECMP@ @@ -474,7 +482,8 @@ Note: This function may, in multibyte locales, return 0 for strings of different lengths! Unlike strcasecmp(), this function works correctly in multibyte locales. */ -extern int mbscasecmp (const char *s1, const char *s2); +extern int mbscasecmp (const char *s1, const char *s2) + _GL_ARG_NONNULL ((1, 2)); #endif #if @GNULIB_MBSNCASECMP@ @@ -487,7 +496,8 @@ of different lengths! Unlike strncasecmp(), this function works correctly in multibyte locales. But beware that N is not a byte count but a character count! */ -extern int mbsncasecmp (const char *s1, const char *s2, size_t n); +extern int mbsncasecmp (const char *s1, const char *s2, size_t n) + _GL_ARG_NONNULL ((1, 2)); #endif #if @GNULIB_MBSPCASECMP@ @@ -500,7 +510,8 @@ smaller length than PREFIX! Unlike strncasecmp(), this function works correctly in multibyte locales. */ -extern char * mbspcasecmp (const char *string, const char *prefix); +extern char * mbspcasecmp (const char *string, const char *prefix) + _GL_ARG_NONNULL ((1, 2)); #endif #if @GNULIB_MBSCASESTR@ @@ -509,7 +520,8 @@ Note: This function may, in multibyte locales, return success even if strlen (haystack) < strlen (needle) ! Unlike strcasestr(), this function works correctly in multibyte locales. */ -extern char * mbscasestr (const char *haystack, const char *needle); +extern char * mbscasestr (const char *haystack, const char *needle) + _GL_ARG_NONNULL ((1, 2)); #endif #if @GNULIB_MBSCSPN@ @@ -518,7 +530,8 @@ beginning of the string to this occurrence, or to the end of the string if none exists. Unlike strcspn(), this function works correctly in multibyte locales. */ -extern size_t mbscspn (const char *string, const char *accept); +extern size_t mbscspn (const char *string, const char *accept) + _GL_ARG_NONNULL ((1, 2)); #endif #if @GNULIB_MBSPBRK@ @@ -527,7 +540,8 @@ exists. Unlike strpbrk(), this function works correctly in multibyte locales. */ # define mbspbrk rpl_mbspbrk /* avoid collision with HP-UX function */ -extern char * mbspbrk (const char *string, const char *accept); +extern char * mbspbrk (const char *string, const char *accept) + _GL_ARG_NONNULL ((1, 2)); #endif #if @GNULIB_MBSSPN@ @@ -536,7 +550,8 @@ beginning of the string to this occurrence, or to the end of the string if none exists. Unlike strspn(), this function works correctly in multibyte locales. */ -extern size_t mbsspn (const char *string, const char *reject); +extern size_t mbsspn (const char *string, const char *reject) + _GL_ARG_NONNULL ((1, 2)); #endif #if @GNULIB_MBSSEP@ @@ -554,7 +569,8 @@ Caveat: The identity of the delimiting character is lost. See also mbstok_r(). */ -extern char * mbssep (char **stringp, const char *delim); +extern char * mbssep (char **stringp, const char *delim) + _GL_ARG_NONNULL ((1, 2)); #endif #if @GNULIB_MBSTOK_R@ @@ -574,7 +590,8 @@ Caveat: The identity of the delimiting character is lost. See also mbssep(). */ -extern char * mbstok_r (char *string, const char *delim, char **save_ptr); +extern char * mbstok_r (char *string, const char *delim, char **save_ptr) + _GL_ARG_NONNULL ((2, 3)); #endif /* Map any int, typically from errno, into an error message. */ @@ -609,7 +626,7 @@ #if @GNULIB_STRVERSCMP@ # if !@HAVE_STRVERSCMP@ -extern int strverscmp (const char *, const char *); +extern int strverscmp (const char *, const char *) _GL_ARG_NONNULL ((1, 2)); # endif #elif defined GNULIB_POSIXCHECK # undef strverscmp
--- a/lib/strings.in.h +++ b/lib/strings.in.h @@ -1,6 +1,6 @@ /* A substitute <strings.h>. - Copyright (C) 2007-2008 Free Software Foundation, Inc. + Copyright (C) 2007-2009 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -31,6 +31,8 @@ /* The definition of GL_LINK_WARNING is copied here. */ +/* The definition of _GL_ARG_NONNULL is copied here. */ + #ifdef __cplusplus extern "C" { @@ -42,7 +44,8 @@ than S2. Note: This function does not work in multibyte locales. */ #if ! @HAVE_STRCASECMP@ -extern int strcasecmp (char const *s1, char const *s2); +extern int strcasecmp (char const *s1, char const *s2) + _GL_ARG_NONNULL ((1, 2)); #endif #if defined GNULIB_POSIXCHECK /* strcasecmp() does not work with multibyte strings: @@ -64,7 +67,8 @@ lexicographically less than, equal to or greater than S2. Note: This function cannot work correctly in multibyte locales. */ #if ! @HAVE_DECL_STRNCASECMP@ -extern int strncasecmp (char const *s1, char const *s2, size_t n); +extern int strncasecmp (char const *s1, char const *s2, size_t n) + _GL_ARG_NONNULL ((1, 2)); #endif #if defined GNULIB_POSIXCHECK /* strncasecmp() does not work with multibyte strings:
--- a/lib/strtod.c +++ b/lib/strtod.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991, 1992, 1997, 1999, 2003, 2006, 2008 Free +/* Copyright (C) 1991-1992, 1997, 1999, 2003, 2006, 2008-2009 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify @@ -16,6 +16,10 @@ #include <config.h> +/* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc + optimizes away the nptr == NULL test below. */ +#define _GL_ARG_NONNULL(params) + #include <stdlib.h> #include <ctype.h>
--- a/lib/sys_socket.in.h +++ b/lib/sys_socket.in.h @@ -43,6 +43,8 @@ #ifndef _GL_SYS_SOCKET_H #define _GL_SYS_SOCKET_H +/* The definition of _GL_ARG_NONNULL is copied here. */ + #if !@HAVE_SA_FAMILY_T@ typedef unsigned short sa_family_t; #endif @@ -195,7 +197,7 @@ # if @HAVE_WINSOCK2_H@ # undef connect # define connect rpl_connect -extern int rpl_connect (int, struct sockaddr *, int); +extern int rpl_connect (int, struct sockaddr *, int) _GL_ARG_NONNULL ((2)); # endif # elif @HAVE_WINSOCK2_H@ # undef connect @@ -229,7 +231,7 @@ # if @HAVE_WINSOCK2_H@ # undef bind # define bind rpl_bind -extern int rpl_bind (int, struct sockaddr *, int); +extern int rpl_bind (int, struct sockaddr *, int) _GL_ARG_NONNULL ((2)); # endif # elif @HAVE_WINSOCK2_H@ # undef bind @@ -246,7 +248,8 @@ # if @HAVE_WINSOCK2_H@ # undef getpeername # define getpeername rpl_getpeername -extern int rpl_getpeername (int, struct sockaddr *, int *); +extern int rpl_getpeername (int, struct sockaddr *, int *) + _GL_ARG_NONNULL ((2, 3)); # endif # elif @HAVE_WINSOCK2_H@ # undef getpeername @@ -263,7 +266,8 @@ # if @HAVE_WINSOCK2_H@ # undef getsockname # define getsockname rpl_getsockname -extern int rpl_getsockname (int, struct sockaddr *, int *); +extern int rpl_getsockname (int, struct sockaddr *, int *) + _GL_ARG_NONNULL ((2, 3)); # endif # elif @HAVE_WINSOCK2_H@ # undef getsockname @@ -280,7 +284,8 @@ # if @HAVE_WINSOCK2_H@ # undef getsockopt # define getsockopt rpl_getsockopt -extern int rpl_getsockopt (int, int, int, void *, socklen_t *); +extern int rpl_getsockopt (int, int, int, void *, socklen_t *) + _GL_ARG_NONNULL ((4, 5)); # endif # elif @HAVE_WINSOCK2_H@ # undef getsockopt @@ -314,7 +319,7 @@ # if @HAVE_WINSOCK2_H@ # undef recv # define recv rpl_recv -extern int rpl_recv (int, void *, int, int); +extern int rpl_recv (int, void *, int, int) _GL_ARG_NONNULL ((2)); # endif # elif @HAVE_WINSOCK2_H@ # undef recv @@ -331,7 +336,7 @@ # if @HAVE_WINSOCK2_H@ # undef send # define send rpl_send -extern int rpl_send (int, const void *, int, int); +extern int rpl_send (int, const void *, int, int) _GL_ARG_NONNULL ((2)); # endif # elif @HAVE_WINSOCK2_H@ # undef send @@ -348,7 +353,8 @@ # if @HAVE_WINSOCK2_H@ # undef recvfrom # define recvfrom rpl_recvfrom -extern int rpl_recvfrom (int, void *, int, int, struct sockaddr *, int *); +extern int rpl_recvfrom (int, void *, int, int, struct sockaddr *, int *) + _GL_ARG_NONNULL ((2)); # endif # elif @HAVE_WINSOCK2_H@ # undef recvfrom @@ -365,7 +371,8 @@ # if @HAVE_WINSOCK2_H@ # undef sendto # define sendto rpl_sendto -extern int rpl_sendto (int, const void *, int, int, struct sockaddr *, int); +extern int rpl_sendto (int, const void *, int, int, struct sockaddr *, int) + _GL_ARG_NONNULL ((2)); # endif # elif @HAVE_WINSOCK2_H@ # undef sendto @@ -382,7 +389,8 @@ # if @HAVE_WINSOCK2_H@ # undef setsockopt # define setsockopt rpl_setsockopt -extern int rpl_setsockopt (int, int, int, const void *, socklen_t); +extern int rpl_setsockopt (int, int, int, const void *, socklen_t) + _GL_ARG_NONNULL ((4)); # endif # elif @HAVE_WINSOCK2_H@ # undef setsockopt
--- a/lib/sys_stat.in.h +++ b/lib/sys_stat.in.h @@ -49,6 +49,8 @@ /* The definition of GL_LINK_WARNING is copied here. */ +/* The definition of _GL_ARG_NONNULL is copied here. */ + /* Before doing "#define mkdir rpl_mkdir" below, we need to include all headers that may declare mkdir(). */ #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ @@ -295,7 +297,8 @@ #if @GNULIB_FCHMODAT@ # if !@HAVE_FCHMODAT@ -extern int fchmodat (int fd, char const *file, mode_t mode, int flag); +extern int fchmodat (int fd, char const *file, mode_t mode, int flag) + _GL_ARG_NONNULL ((2)); # endif #elif defined GNULIB_POSIXCHECK # undef fchmodat @@ -308,7 +311,7 @@ #if @REPLACE_FSTAT@ # define fstat rpl_fstat -extern int fstat (int fd, struct stat *buf); +extern int fstat (int fd, struct stat *buf) _GL_ARG_NONNULL ((2)); #endif @@ -318,7 +321,8 @@ # define fstatat rpl_fstatat # endif # if !@HAVE_FSTATAT@ || @REPLACE_FSTATAT@ -extern int fstatat (int fd, char const *name, struct stat *st, int flags); +extern int fstatat (int fd, char const *name, struct stat *st, int flags) + _GL_ARG_NONNULL ((2, 3)); # endif #elif defined GNULIB_POSIXCHECK # undef fstatat @@ -360,7 +364,7 @@ # define lchmod chmod # endif # if 0 /* assume already declared */ -extern int lchmod (const char *filename, mode_t mode); +extern int lchmod (const char *filename, mode_t mode) _GL_ARG_NONNULL ((1)); # endif #elif defined GNULIB_POSIXCHECK # undef lchmod @@ -379,7 +383,8 @@ # elif @REPLACE_LSTAT@ # undef lstat # define lstat rpl_lstat -extern int rpl_lstat (const char *name, struct stat *buf); +extern int rpl_lstat (const char *name, struct stat *buf) + _GL_ARG_NONNULL ((1, 2)); # endif #elif defined GNULIB_POSIXCHECK # undef lstat @@ -393,7 +398,7 @@ #if @REPLACE_MKDIR@ # undef mkdir # define mkdir rpl_mkdir -extern int mkdir (char const *name, mode_t mode); +extern int mkdir (char const *name, mode_t mode) _GL_ARG_NONNULL ((1)); #else /* mingw's _mkdir() function has 1 argument, but we pass 2 arguments. Additionally, it declares _mkdir (and depending on compile flags, an @@ -413,7 +418,8 @@ #if @GNULIB_MKDIRAT@ # if !@HAVE_MKDIRAT@ -extern int mkdirat (int fd, char const *file, mode_t mode); +extern int mkdirat (int fd, char const *file, mode_t mode) + _GL_ARG_NONNULL ((2)); # endif #elif defined GNULIB_POSIXCHECK # undef mkdirat @@ -430,7 +436,7 @@ # define mkfifo rpl_mkfifo # endif # if !@HAVE_MKFIFO@ || @REPLACE_MKFIFO@ -int mkfifo (char const *file, mode_t mode); +extern int mkfifo (char const *file, mode_t mode) _GL_ARG_NONNULL ((1)); # endif #elif defined GNULIB_POSIXCHECK # undef mkfifo @@ -443,7 +449,8 @@ #if @GNULIB_MKFIFOAT@ # if !@HAVE_MKFIFOAT@ -int mkfifoat (int fd, char const *file, mode_t mode); +extern int mkfifoat (int fd, char const *file, mode_t mode) + _GL_ARG_NONNULL ((2)); # endif #elif defined GNULIB_POSIXCHECK # undef mkfifoat @@ -460,7 +467,8 @@ # define mknod rpl_mknod # endif # if !@HAVE_MKNOD@ || @REPLACE_MKNOD@ -int mknod (char const *file, mode_t mode, dev_t dev); +extern int mknod (char const *file, mode_t mode, dev_t dev) + _GL_ARG_NONNULL ((1)); # endif #elif defined GNULIB_POSIXCHECK # undef mknod @@ -473,7 +481,8 @@ #if @GNULIB_MKNODAT@ # if !@HAVE_MKNODAT@ -int mknodat (int fd, char const *file, mode_t mode, dev_t dev); +extern int mknodat (int fd, char const *file, mode_t mode, dev_t dev) + _GL_ARG_NONNULL ((2)); # endif #elif defined GNULIB_POSIXCHECK # undef mknodat @@ -499,7 +508,7 @@ # else /* !_LARGE_FILES */ # define stat(name, st) rpl_stat (name, st) # endif /* !_LARGE_FILES */ -extern int stat (const char *name, struct stat *buf); +extern int stat (const char *name, struct stat *buf) _GL_ARG_NONNULL ((1, 2)); # endif #elif defined GNULIB_POSIXCHECK # undef stat @@ -517,7 +526,8 @@ # endif # if !@HAVE_UTIMENSAT@ || @REPLACE_UTIMENSAT@ extern int utimensat (int fd, char const *name, - struct timespec const times[2], int flag); + struct timespec const times[2], int flag) + _GL_ARG_NONNULL ((2)); # endif #elif defined GNULIB_POSIXCHECK # undef utimensat
--- a/lib/sys_time.in.h +++ b/lib/sys_time.in.h @@ -1,6 +1,6 @@ /* Provide a more complete sys/time.h. - Copyright (C) 2007-2008 Free Software Foundation, Inc. + Copyright (C) 2007-2009 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -39,6 +39,8 @@ # include <time.h> # endif +/* The definition of _GL_ARG_NONNULL is copied here. */ + #ifdef __cplusplus extern "C" { #endif @@ -54,7 +56,8 @@ # if @REPLACE_GETTIMEOFDAY@ # undef gettimeofday # define gettimeofday rpl_gettimeofday -int gettimeofday (struct timeval *restrict, void *restrict); +extern int gettimeofday (struct timeval *restrict, void *restrict) + _GL_ARG_NONNULL ((1)); # endif #ifdef __cplusplus
--- a/lib/sys_times.in.h +++ b/lib/sys_times.in.h @@ -1,5 +1,5 @@ /* Provide a sys/times.h header file. - Copyright (C) 2008 Free Software Foundation, Inc. + Copyright (C) 2008-2009 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -28,6 +28,8 @@ /* The definition of GL_LINK_WARNING is copied here. */ +/* The definition of _GL_ARG_NONNULL is copied here. */ + # ifdef __cplusplus extern "C" { # endif @@ -43,7 +45,7 @@ }; # if @GNULIB_TIMES@ - extern clock_t times (struct tms *buffer); + extern clock_t times (struct tms *buffer) _GL_ARG_NONNULL ((1)); # elif defined GNULIB_POSIXCHECK # undef times # define times(s) \
--- a/lib/sys_utsname.in.h +++ b/lib/sys_utsname.in.h @@ -20,6 +20,8 @@ /* The definition of GL_LINK_WARNING is copied here. */ +/* The definition of _GL_ARG_NONNULL is copied here. */ + #ifdef __cplusplus extern "C" { @@ -65,7 +67,7 @@ #if @GNULIB_UNAME@ # if !@HAVE_UNAME@ -extern int uname (struct utsname *buf); +extern int uname (struct utsname *buf) _GL_ARG_NONNULL ((1)); # endif #elif defined GNULIB_POSIXCHECK # undef uname
--- a/lib/time.in.h +++ b/lib/time.in.h @@ -40,6 +40,8 @@ /* NetBSD 5.0 mis-defines NULL. */ #include <stddef.h> +/* The definition of _GL_ARG_NONNULL is copied here. */ + # ifdef __cplusplus extern "C" { # endif @@ -66,13 +68,14 @@ <http://www.opengroup.org/susv3xsh/nanosleep.html>. */ # if @REPLACE_NANOSLEEP@ # define nanosleep rpl_nanosleep -int nanosleep (struct timespec const *__rqtp, struct timespec *__rmtp); +extern int nanosleep (struct timespec const *__rqtp, struct timespec *__rmtp) + _GL_ARG_NONNULL ((1)); # endif /* Return the 'time_t' representation of TP and normalize TP. */ # if @REPLACE_MKTIME@ # define mktime rpl_mktime -extern time_t mktime (struct tm *__tp); +extern time_t mktime (struct tm *__tp) _GL_ARG_NONNULL ((1)); # endif /* Convert TIMER to RESULT, assuming local time and UTC respectively. See @@ -83,10 +86,12 @@ # define localtime_r rpl_localtime_r # undef gmtime_r # define gmtime_r rpl_gmtime_r -struct tm *localtime_r (time_t const *restrict __timer, - struct tm *restrict __result); -struct tm *gmtime_r (time_t const *restrict __timer, - struct tm *restrict __result); +extern struct tm *localtime_r (time_t const *restrict __timer, + struct tm *restrict __result) + _GL_ARG_NONNULL ((1, 2)); +extern struct tm *gmtime_r (time_t const *restrict __timer, + struct tm *restrict __result) + _GL_ARG_NONNULL ((1, 2)); # endif /* Parse BUF as a time stamp, assuming FORMAT specifies its layout, and store @@ -95,15 +100,17 @@ # if @REPLACE_STRPTIME@ # undef strptime # define strptime rpl_strptime -char *strptime (char const *restrict __buf, char const *restrict __format, - struct tm *restrict __tm); +extern char *strptime (char const *restrict __buf, + char const *restrict __format, + struct tm *restrict __tm) + _GL_ARG_NONNULL ((1, 2, 3)); # endif /* Convert TM to a time_t value, assuming UTC. */ # if @REPLACE_TIMEGM@ # undef timegm # define timegm rpl_timegm -time_t timegm (struct tm *__tm); +extern time_t timegm (struct tm *__tm) _GL_ARG_NONNULL ((1)); # endif /* Encourage applications to avoid unsafe functions that can overrun
--- a/lib/tsearch.c +++ b/lib/tsearch.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1995-1997, 2000, 2006-2007 Free Software Foundation, Inc. +/* Copyright (C) 1995-1997, 2000, 2006-2007, 2009 Free Software Foundation, Inc. Contributed by Bernd Schmidt <crux@Pool.Informatik.RWTH-Aachen.DE>, 1997. NOTE: The canonical source of this file is maintained with the GNU C @@ -86,6 +86,10 @@ #include <config.h> +/* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc + optimizes away the rootp == NULL tests below. */ +#define _GL_ARG_NONNULL(params) + /* Specification. */ #ifdef IN_LIBINTL # include "tsearch.h"
--- a/lib/unistd.in.h +++ b/lib/unistd.in.h @@ -96,6 +96,8 @@ /* The definition of GL_LINK_WARNING is copied here. */ +/* The definition of _GL_ARG_NONNULL is copied here. */ + /* OS/2 EMX lacks these macros. */ #ifndef STDIN_FILENO @@ -135,7 +137,8 @@ Return 0 if successful, otherwise -1 and errno set. See the POSIX:2001 specification <http://www.opengroup.org/susv3xsh/chown.html>. */ -extern int chown (const char *file, uid_t uid, gid_t gid); +extern int chown (const char *file, uid_t uid, gid_t gid) + _GL_ARG_NONNULL ((1)); # endif #elif defined GNULIB_POSIXCHECK # undef chown @@ -239,7 +242,7 @@ # if !@HAVE_EUIDACCESS@ /* Like access(), except that it uses the effective user id and group id of the current process. */ -extern int euidaccess (const char *filename, int mode); +extern int euidaccess (const char *filename, int mode) _GL_ARG_NONNULL ((1)); # endif #elif defined GNULIB_POSIXCHECK # undef euidaccess @@ -252,7 +255,8 @@ #if @GNULIB_FACCESSAT@ # if !@HAVE_FACCESSAT@ -int faccessat (int fd, char const *file, int mode, int flag); +extern int faccessat (int fd, char const *file, int mode, int flag) + _GL_ARG_NONNULL ((2)); # endif #elif defined GNULIB_POSIXCHECK # undef faccessat @@ -273,7 +277,8 @@ extern int fchdir (int /*fd*/); /* Gnulib internal hooks needed to maintain the fchdir metadata. */ -extern int _gl_register_fd (int fd, const char *filename); +extern int _gl_register_fd (int fd, const char *filename) + _GL_ARG_NONNULL ((2)); extern void _gl_unregister_fd (int fd); extern int _gl_register_dup (int oldfd, int newfd); extern const char *_gl_directory_name (int fd); @@ -294,7 +299,8 @@ # define fchownat rpl_fchownat # endif # if !@HAVE_FCHOWNAT@ || @REPLACE_FCHOWNAT@ -extern int fchownat (int fd, char const *file, uid_t owner, gid_t group, int flag); +extern int fchownat (int fd, char const *file, uid_t owner, gid_t group, int flag) + _GL_ARG_NONNULL ((2)); # endif #elif defined GNULIB_POSIXCHECK # undef fchownat @@ -378,7 +384,7 @@ If the NIS domain name is longer than LEN, set errno = EINVAL and return -1. Return 0 if successful, otherwise set errno and return -1. */ # if !@HAVE_GETDOMAINNAME@ -extern int getdomainname(char *name, size_t len); +extern int getdomainname(char *name, size_t len) _GL_ARG_NONNULL ((1)); # endif #elif defined GNULIB_POSIXCHECK # undef getdomainname @@ -439,7 +445,7 @@ # define gethostname rpl_gethostname # endif # if @UNISTD_H_HAVE_WINSOCK2_H@ || !@HAVE_GETHOSTNAME@ -extern int gethostname(char *name, size_t len); +extern int gethostname(char *name, size_t len) _GL_ARG_NONNULL ((1)); # endif #elif @UNISTD_H_HAVE_WINSOCK2_H@ # undef gethostname @@ -464,7 +470,7 @@ See <http://www.opengroup.org/susv3xsh/getlogin.html>. */ # if !@HAVE_DECL_GETLOGIN_R@ -extern int getlogin_r (char *name, size_t size); +extern int getlogin_r (char *name, size_t size) _GL_ARG_NONNULL ((1)); # endif #elif defined GNULIB_POSIXCHECK # undef getlogin_r @@ -574,7 +580,8 @@ Return 0 if successful, otherwise -1 and errno set. See the POSIX:2001 specification <http://www.opengroup.org/susv3xsh/lchown.html>. */ -extern int lchown (char const *file, uid_t owner, gid_t group); +extern int lchown (char const *file, uid_t owner, gid_t group) + _GL_ARG_NONNULL ((1)); # endif #elif defined GNULIB_POSIXCHECK # undef lchown @@ -594,7 +601,8 @@ See POSIX:2001 specification <http://www.opengroup.org/susv3xsh/link.html>. */ # if !@HAVE_LINK@ || @REPLACE_LINK@ -extern int link (const char *path1, const char *path2); +extern int link (const char *path1, const char *path2) + _GL_ARG_NONNULL ((1, 2)); # endif #elif defined GNULIB_POSIXCHECK # undef link @@ -614,7 +622,8 @@ Return 0 if successful, otherwise -1 and errno set. */ # if !@HAVE_LINKAT@ || @REPLACE_LINKAT@ extern int linkat (int fd1, const char *path1, int fd2, const char *path2, - int flag); + int flag) + _GL_ARG_NONNULL ((2, 4)); # endif #elif defined GNULIB_POSIXCHECK # undef linkat @@ -654,7 +663,7 @@ # if @HAVE_PIPE2@ # define pipe2 rpl_pipe2 # endif -extern int pipe2 (int fd[2], int flags); +extern int pipe2 (int fd[2], int flags) _GL_ARG_NONNULL ((1)); #elif defined GNULIB_POSIXCHECK # undef pipe2 # define pipe2(f,o) \ @@ -673,7 +682,8 @@ set errno and return -1. 0 indicates EOF. See the POSIX:2001 specification <http://www.opengroup.org/susv3xsh/pread.html>. */ # if !@HAVE_PREAD@ || @REPLACE_PREAD@ - extern ssize_t pread (int fd, void *buf, size_t bufsize, off_t offset); + extern ssize_t pread (int fd, void *buf, size_t bufsize, off_t offset) + _GL_ARG_NONNULL ((2)); # endif #elif defined GNULIB_POSIXCHECK # undef pread @@ -694,7 +704,8 @@ See the POSIX:2001 specification <http://www.opengroup.org/susv3xsh/readlink.html>. */ # if !@HAVE_READLINK@ || @REPLACE_READLINK@ -extern ssize_t readlink (const char *file, char *buf, size_t bufsize); +extern ssize_t readlink (const char *file, char *buf, size_t bufsize) + _GL_ARG_NONNULL ((1, 2)); # endif #elif defined GNULIB_POSIXCHECK # undef readlink @@ -707,7 +718,8 @@ #if @GNULIB_READLINKAT@ # if !@HAVE_READLINKAT@ -ssize_t readlinkat (int fd, char const *file, char *buf, size_t len); +extern ssize_t readlinkat (int fd, char const *file, char *buf, size_t len) + _GL_ARG_NONNULL ((2, 3)); # endif #elif defined GNULIB_POSIXCHECK # undef readlinkat @@ -722,7 +734,7 @@ # if @REPLACE_RMDIR@ # define rmdir rpl_rmdir /* Remove the directory DIR. */ -extern int rmdir (char const *name); +extern int rmdir (char const *name) _GL_ARG_NONNULL ((1)); # endif #elif defined GNULIB_POSIXCHECK # undef rmdir @@ -760,7 +772,8 @@ # define symlink rpl_symlink # endif # if !@HAVE_SYMLINK@ || @REPLACE_SYMLINK@ -int symlink (char const *contents, char const *file); +extern int symlink (char const *contents, char const *file) + _GL_ARG_NONNULL ((1, 2)); # endif #elif defined GNULIB_POSIXCHECK # undef symlink @@ -773,7 +786,8 @@ #if @GNULIB_SYMLINKAT@ # if !@HAVE_SYMLINKAT@ -int symlinkat (char const *contents, int fd, char const *file); +extern int symlinkat (char const *contents, int fd, char const *file) + _GL_ARG_NONNULL ((1, 3)); # endif #elif defined GNULIB_POSIXCHECK # undef symlinkat @@ -788,7 +802,7 @@ # if @REPLACE_UNLINK@ # undef unlink # define unlink rpl_unlink -extern int unlink (char const *file); +extern int unlink (char const *file) _GL_ARG_NONNULL ((1)); # endif #elif defined GNULIB_POSIXCHECK # undef unlink @@ -805,7 +819,7 @@ # define unlinkat rpl_unlinkat # endif # if !@HAVE_UNLINKAT@ || @REPLACE_UNLINKAT@ -extern int unlinkat (int fd, char const *file, int flag); +extern int unlinkat (int fd, char const *file, int flag) _GL_ARG_NONNULL ((2)); # endif #elif defined GNULIB_POSIXCHECK # undef unlinkat @@ -843,7 +857,8 @@ <http://www.opengroup.org/susv3xsh/write.html>. */ # undef write # define write rpl_write -extern ssize_t write (int fd, const void *buf, size_t count); +extern ssize_t write (int fd, const void *buf, size_t count) + _GL_ARG_NONNULL ((2)); #endif
--- a/lib/unsetenv.c +++ b/lib/unsetenv.c @@ -16,6 +16,10 @@ #include <config.h> +/* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc + optimizes away the name == NULL test below. */ +#define _GL_ARG_NONNULL(params) + /* Specification. */ #include <stdlib.h>
--- a/lib/wchar.in.h +++ b/lib/wchar.in.h @@ -74,6 +74,8 @@ /* The definition of GL_LINK_WARNING is copied here. */ +/* The definition of _GL_ARG_NONNULL is copied here. */ + #ifdef __cplusplus extern "C" { #endif @@ -197,7 +199,8 @@ # define mbsrtowcs rpl_mbsrtowcs # endif # if !@HAVE_MBSRTOWCS@ || @REPLACE_MBSRTOWCS@ -extern size_t mbsrtowcs (wchar_t *dest, const char **srcp, size_t len, mbstate_t *ps); +extern size_t mbsrtowcs (wchar_t *dest, const char **srcp, size_t len, mbstate_t *ps) + _GL_ARG_NONNULL ((2)); # endif #elif defined GNULIB_POSIXCHECK # undef mbsrtowcs @@ -215,7 +218,8 @@ # define mbsnrtowcs rpl_mbsnrtowcs # endif # if !@HAVE_MBSNRTOWCS@ || @REPLACE_MBSNRTOWCS@ -extern size_t mbsnrtowcs (wchar_t *dest, const char **srcp, size_t srclen, size_t len, mbstate_t *ps); +extern size_t mbsnrtowcs (wchar_t *dest, const char **srcp, size_t srclen, size_t len, mbstate_t *ps) + _GL_ARG_NONNULL ((2)); # endif #elif defined GNULIB_POSIXCHECK # undef mbsnrtowcs @@ -251,7 +255,8 @@ # define wcsrtombs rpl_wcsrtombs # endif # if !@HAVE_WCSRTOMBS@ || @REPLACE_WCSRTOMBS@ -extern size_t wcsrtombs (char *dest, const wchar_t **srcp, size_t len, mbstate_t *ps); +extern size_t wcsrtombs (char *dest, const wchar_t **srcp, size_t len, mbstate_t *ps) + _GL_ARG_NONNULL ((2)); # endif #elif defined GNULIB_POSIXCHECK # undef wcsrtombs @@ -269,7 +274,8 @@ # define wcsnrtombs rpl_wcsnrtombs # endif # if !@HAVE_WCSNRTOMBS@ || @REPLACE_WCSNRTOMBS@ -extern size_t wcsnrtombs (char *dest, const wchar_t **srcp, size_t srclen, size_t len, mbstate_t *ps); +extern size_t wcsnrtombs (char *dest, const wchar_t **srcp, size_t srclen, size_t len, mbstate_t *ps) + _GL_ARG_NONNULL ((2)); # endif #elif defined GNULIB_POSIXCHECK # undef wcsnrtombs
new file mode 100644 --- /dev/null +++ b/modules/arg-nonnull @@ -0,0 +1,31 @@ +Description: +A C macro for declaring that specific arguments must not be NULL. + +Files: +build-aux/arg-nonnull.h + +Depends-on: + +configure.ac: + +Makefile.am: +BUILT_SOURCES += arg-nonnull.h +# The arg-nonnull.h that gets inserted into generated .h files is the same as +# build-aux/arg-nonnull.h, except that it has the copyright header cut off. +arg-nonnull.h: $(top_srcdir)/build-aux/arg-nonnull.h + $(AM_V_GEN)rm -f $@-t $@ && \ + sed -n -e '/GL_ARG_NONNULL/,$$p' \ + < $(top_srcdir)/build-aux/arg-nonnull.h \ + > $@-t && \ + mv $@-t $@ +MOSTLYCLEANFILES += arg-nonnull.h arg-nonnull.h-t + +ARG_NONNULL_H=arg-nonnull.h + +Include: + +License: +LGPLv2+ + +Maintainer: +Bruno Haible
--- a/modules/argv-iter +++ b/modules/argv-iter @@ -6,6 +6,7 @@ lib/argv-iter.h Depends-on: +arg-nonnull getdelim stdbool
--- a/modules/arpa_inet +++ b/modules/arpa_inet @@ -8,6 +8,7 @@ Depends-on: include_next link-warning +arg-nonnull sys_socket configure.ac: @@ -19,7 +20,7 @@ # We need the following in order to create <arpa/inet.h> when the system # doesn't have one. -arpa/inet.h: arpa_inet.in.h $(LINK_WARNING_H) +arpa/inet.h: arpa_inet.in.h $(LINK_WARNING_H) $(ARG_NONNULL_H) $(AM_V_at)$(MKDIR_P) arpa $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ @@ -32,6 +33,7 @@ -e 's|@''HAVE_DECL_INET_NTOP''@|$(HAVE_DECL_INET_NTOP)|g' \ -e 's|@''HAVE_DECL_INET_PTON''@|$(HAVE_DECL_INET_PTON)|g' \ -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ < $(srcdir)/arpa_inet.in.h; \ } > $@-t && \ mv $@-t $@
--- a/modules/dirent +++ b/modules/dirent @@ -9,6 +9,7 @@ Depends-on: include_next link-warning +arg-nonnull configure.ac: gl_DIRENT_H @@ -18,7 +19,7 @@ # We need the following in order to create <dirent.h> when the system # doesn't have one that works with the given compiler. -dirent.h: dirent.in.h $(LINK_WARNING_H) +dirent.h: dirent.in.h $(LINK_WARNING_H) $(ARG_NONNULL_H) $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ @@ -36,6 +37,7 @@ -e 's|@''REPLACE_FDOPENDIR''@|$(REPLACE_FDOPENDIR)|g' \ -e 's|@''REPLACE_OPENDIR''@|$(REPLACE_OPENDIR)|g' \ -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ < $(srcdir)/dirent.in.h; \ } > $@-t && \ mv $@-t $@
--- a/modules/fcntl-h +++ b/modules/fcntl-h @@ -8,6 +8,7 @@ Depends-on: include_next link-warning +arg-nonnull unistd extensions @@ -19,7 +20,7 @@ # We need the following in order to create <fcntl.h> when the system # doesn't have one that works with the given compiler. -fcntl.h: fcntl.in.h $(LINK_WARNING_H) +fcntl.h: fcntl.in.h $(LINK_WARNING_H) $(ARG_NONNULL_H) $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ @@ -31,6 +32,7 @@ -e 's|@''REPLACE_OPENAT''@|$(REPLACE_OPENAT)|g' \ -e 's|@''HAVE_OPENAT''@|$(HAVE_OPENAT)|g' \ -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ < $(srcdir)/fcntl.in.h; \ } > $@-t && \ mv $@-t $@
--- a/modules/fnmatch +++ b/modules/fnmatch @@ -9,6 +9,7 @@ m4/fnmatch.m4 Depends-on: +arg-nonnull extensions alloca stdbool @@ -27,10 +28,11 @@ # We need the following in order to create <fnmatch.h> when the system # doesn't have one that supports the required API. -fnmatch.h: fnmatch.in.h +fnmatch.h: fnmatch.in.h $(ARG_NONNULL_H) $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ - cat $(srcdir)/fnmatch.in.h; \ + sed -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ + < $(srcdir)/fnmatch.in.h; \ } > $@-t && \ mv -f $@-t $@ MOSTLYCLEANFILES += fnmatch.h fnmatch.h-t
--- a/modules/getopt-posix +++ b/modules/getopt-posix @@ -13,6 +13,7 @@ unistd extensions include_next +arg-nonnull configure.ac: gl_FUNC_GETOPT_POSIX @@ -22,7 +23,7 @@ # We need the following in order to create <getopt.h> when the system # doesn't have one that works with the given compiler. -getopt.h: getopt.in.h $(LINK_WARNING_H) +getopt.h: getopt.in.h $(LINK_WARNING_H) $(ARG_NONNULL_H) $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ sed -e 's|@''HAVE_GETOPT_H''@|$(HAVE_GETOPT_H)|g' \ @@ -30,6 +31,7 @@ -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ -e 's|@''NEXT_GETOPT_H''@|$(NEXT_GETOPT_H)|g' \ -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ < $(srcdir)/getopt.in.h; \ } > $@-t && \ mv -f $@-t $@
--- a/modules/glob +++ b/modules/glob @@ -10,6 +10,7 @@ Depends-on: alloca +arg-nonnull d-type dirfd extensions @@ -31,10 +32,11 @@ # We need the following in order to create <glob.h> when the system # doesn't have one that works with the given compiler. -glob.h: glob.in.h +glob.h: glob.in.h $(ARG_NONNULL_H) $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ sed -e 's|@''HAVE_SYS_CDEFS_H''@|$(HAVE_SYS_CDEFS_H)|g' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ < $(srcdir)/glob.in.h; \ } > $@-t && \ mv -f $@-t $@
--- a/modules/iconv_open +++ b/modules/iconv_open @@ -15,6 +15,7 @@ Depends-on: gperf include_next +arg-nonnull iconv c-ctype c-strcase @@ -28,7 +29,7 @@ # We need the following in order to create <iconv.h> when the system # doesn't have one that works with the given compiler. -iconv.h: iconv.in.h +iconv.h: iconv.in.h $(ARG_NONNULL_H) $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ @@ -38,6 +39,7 @@ -e 's|@''REPLACE_ICONV''@|$(REPLACE_ICONV)|g' \ -e 's|@''REPLACE_ICONV_OPEN''@|$(REPLACE_ICONV_OPEN)|g' \ -e 's|@''REPLACE_ICONV_UTF''@|$(REPLACE_ICONV_UTF)|g' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ < $(srcdir)/iconv.in.h; \ } > $@-t && \ mv $@-t $@
--- a/modules/inttypes +++ b/modules/inttypes @@ -9,6 +9,7 @@ Depends-on: include_next link-warning +arg-nonnull multiarch stdint @@ -20,7 +21,7 @@ # We need the following in order to create <inttypes.h> when the system # doesn't have one that works with the given compiler. -inttypes.h: inttypes.in.h $(LINK_WARNING_H) +inttypes.h: inttypes.in.h $(LINK_WARNING_H) $(ARG_NONNULL_H) $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ sed -e 's/@''HAVE_INTTYPES_H''@/$(HAVE_INTTYPES_H)/g' \ @@ -45,6 +46,7 @@ -e 's/@''UINT32_MAX_LT_UINTMAX_MAX''@/$(UINT32_MAX_LT_UINTMAX_MAX)/g' \ -e 's/@''UINT64_MAX_EQ_ULONG_MAX''@/$(UINT64_MAX_EQ_ULONG_MAX)/g' \ -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ < $(srcdir)/inttypes.in.h; \ } > $@-t && \ mv $@-t $@
--- a/modules/locale +++ b/modules/locale @@ -7,6 +7,7 @@ Depends-on: include_next +arg-nonnull extensions stddef @@ -18,7 +19,7 @@ # We need the following in order to create <locale.h> when the system # doesn't have one that provides all definitions. -locale.h: locale.in.h +locale.h: locale.in.h $(ARG_NONNULL_H) $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ @@ -27,6 +28,7 @@ -e 's|@''GNULIB_DUPLOCALE''@|$(GNULIB_DUPLOCALE)|g' \ -e 's|@''HAVE_XLOCALE_H''@|$(HAVE_XLOCALE_H)|g' \ -e 's|@''REPLACE_DUPLOCALE''@|$(REPLACE_DUPLOCALE)|g' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ < $(srcdir)/locale.in.h; \ } > $@-t && \ mv $@-t $@
--- a/modules/math +++ b/modules/math @@ -8,6 +8,7 @@ Depends-on: include_next link-warning +arg-nonnull configure.ac: gl_MATH_H @@ -17,7 +18,7 @@ # We need the following in order to create <math.h> when the system # doesn't have one that works with the given compiler. -math.h: math.in.h $(LINK_WARNING_H) +math.h: math.in.h $(LINK_WARNING_H) $(ARG_NONNULL_H) $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ sed -e 's|@''INCLUDE_NEXT_AS_FIRST_DIRECTIVE''@|$(INCLUDE_NEXT_AS_FIRST_DIRECTIVE)|g' \ @@ -79,6 +80,7 @@ -e 's|@''REPLACE_SIGNBIT_USING_GCC''@|$(REPLACE_SIGNBIT_USING_GCC)|g' \ -e 's|@''REPLACE_TRUNCL''@|$(REPLACE_TRUNCL)|g' \ -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ < $(srcdir)/math.in.h; \ } > $@-t && \ mv $@-t $@
--- a/modules/netdb +++ b/modules/netdb @@ -7,6 +7,7 @@ Depends-on: include_next +arg-nonnull sys_socket configure.ac: @@ -17,7 +18,7 @@ # We need the following in order to create <netdb.h> when the system # doesn't have one that works with the given compiler. -netdb.h: netdb.in.h +netdb.h: netdb.in.h $(ARG_NONNULL_H) $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ @@ -30,6 +31,7 @@ -e 's|@''HAVE_DECL_GAI_STRERROR''@|$(HAVE_DECL_GAI_STRERROR)|g' \ -e 's|@''HAVE_DECL_GETADDRINFO''@|$(HAVE_DECL_GETADDRINFO)|g' \ -e 's|@''HAVE_DECL_GETNAMEINFO''@|$(HAVE_DECL_GETNAMEINFO)|g' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ < $(srcdir)/netdb.in.h; \ } > $@-t && \ mv $@-t $@
--- a/modules/search +++ b/modules/search @@ -8,6 +8,7 @@ Depends-on: include_next link-warning +arg-nonnull configure.ac: gl_SEARCH_H @@ -17,7 +18,7 @@ # We need the following in order to create <search.h> when the system # doesn't have one that works with the given compiler. -search.h: search.in.h $(LINK_WARNING_H) +search.h: search.in.h $(LINK_WARNING_H) $(ARG_NONNULL_H) $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ sed -e 's|@''HAVE_SEARCH_H''@|$(HAVE_SEARCH_H)|g' \ @@ -28,6 +29,7 @@ -e 's|@''HAVE_TSEARCH''@|$(HAVE_TSEARCH)|g' \ -e 's|@''REPLACE_TSEARCH''@|$(REPLACE_TSEARCH)|g' \ -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ < $(srcdir)/search.in.h; \ } > $@-t && \ mv $@-t $@
--- a/modules/signal +++ b/modules/signal @@ -8,6 +8,7 @@ Depends-on: include_next link-warning +arg-nonnull configure.ac: gl_SIGNAL_H @@ -17,7 +18,7 @@ # We need the following in order to create <signal.h> when the system # doesn't have a complete one. -signal.h: signal.in.h $(LINK_WARNING_H) +signal.h: signal.in.h $(LINK_WARNING_H) $(ARG_NONNULL_H) $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ @@ -33,6 +34,7 @@ -e 's|@''HAVE_STRUCT_SIGACTION_SA_SIGACTION''@|$(HAVE_STRUCT_SIGACTION_SA_SIGACTION)|g' \ -e 's|@''HAVE_TYPE_VOLATILE_SIG_ATOMIC_T''@|$(HAVE_TYPE_VOLATILE_SIG_ATOMIC_T)|g' \ -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ < $(srcdir)/signal.in.h; \ } > $@-t && \ mv $@-t $@
--- a/modules/spawn +++ b/modules/spawn @@ -8,6 +8,7 @@ Depends-on: include_next link-warning +arg-nonnull sched configure.ac: @@ -18,7 +19,7 @@ # We need the following in order to create a replacement for <spawn.h> when # the system doesn't have one. -spawn.h: spawn.in.h $(LINK_WARNING_H) +spawn.h: spawn.in.h $(LINK_WARNING_H) $(ARG_NONNULL_H) $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ sed -e 's|@''HAVE_SPAWN_H''@|$(HAVE_SPAWN_H)|g' \ @@ -49,6 +50,7 @@ -e 's|@''HAVE_POSIX_SPAWN''@|$(HAVE_POSIX_SPAWN)|g' \ -e 's|@''REPLACE_POSIX_SPAWN''@|$(REPLACE_POSIX_SPAWN)|g' \ -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ < $(srcdir)/spawn.in.h; \ } > $@-t && \ mv $@-t $@
--- a/modules/stdio +++ b/modules/stdio @@ -9,6 +9,7 @@ Depends-on: include_next link-warning +arg-nonnull raise stddef @@ -20,7 +21,7 @@ # We need the following in order to create <stdio.h> when the system # doesn't have one that works with the given compiler. -stdio.h: stdio.in.h $(LINK_WARNING_H) +stdio.h: stdio.in.h $(LINK_WARNING_H) $(ARG_NONNULL_H) $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ @@ -105,6 +106,7 @@ -e 's|@''REPLACE_VSNPRINTF''@|$(REPLACE_VSNPRINTF)|g' \ -e 's|@''REPLACE_VSPRINTF''@|$(REPLACE_VSPRINTF)|g' \ -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ < $(srcdir)/stdio.in.h; \ } > $@-t && \ mv $@-t $@
--- a/modules/stdlib +++ b/modules/stdlib @@ -8,6 +8,7 @@ Depends-on: include_next link-warning +arg-nonnull unistd stddef stdint @@ -20,7 +21,7 @@ # We need the following in order to create <stdlib.h> when the system # doesn't have one that works with the given compiler. -stdlib.h: stdlib.in.h $(LINK_WARNING_H) +stdlib.h: stdlib.in.h $(LINK_WARNING_H) $(ARG_NONNULL_H) $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ @@ -77,6 +78,7 @@ -e 's|@''REPLACE_STRTOD''@|$(REPLACE_STRTOD)|g' \ -e 's|@''REPLACE_UNSETENV''@|$(REPLACE_UNSETENV)|g' \ -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ < $(srcdir)/stdlib.in.h; \ } > $@-t && \ mv $@-t $@
--- a/modules/string +++ b/modules/string @@ -9,6 +9,7 @@ extensions include_next link-warning +arg-nonnull stddef configure.ac: @@ -19,7 +20,7 @@ # We need the following in order to create <string.h> when the system # doesn't have one that works with the given compiler. -string.h: string.in.h $(LINK_WARNING_H) +string.h: string.in.h $(LINK_WARNING_H) $(ARG_NONNULL_H) $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ @@ -86,6 +87,7 @@ -e 's|@''REPLACE_STRTOK_R''@|$(REPLACE_STRTOK_R)|g' \ -e 's|@''UNDEFINE_STRTOK_R''@|$(UNDEFINE_STRTOK_R)|g' \ -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ < $(srcdir)/string.in.h; \ } > $@-t && \ mv $@-t $@
--- a/modules/strings +++ b/modules/strings @@ -8,6 +8,7 @@ Depends-on: include_next link-warning +arg-nonnull configure.ac: gl_HEADER_STRINGS_H @@ -17,7 +18,7 @@ # We need the following in order to create <strings.h> when the system # doesn't have one that works with the given compiler. -strings.h: strings.in.h $(LINK_WARNING_H) +strings.h: strings.in.h $(LINK_WARNING_H) $(ARG_NONNULL_H) $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ @@ -26,6 +27,7 @@ -e 's|@''HAVE_STRCASECMP''@|$(HAVE_STRCASECMP)|g' \ -e 's|@''HAVE_DECL_STRNCASECMP''@|$(HAVE_DECL_STRNCASECMP)|g' \ -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ < $(srcdir)/strings.in.h; \ } > $@-t && \ mv $@-t $@
--- a/modules/sys_socket +++ b/modules/sys_socket @@ -9,6 +9,7 @@ Depends-on: include_next link-warning +arg-nonnull errno alignof @@ -21,7 +22,7 @@ # We need the following in order to create <sys/socket.h> when the system # doesn't have one that works with the given compiler. -sys/socket.h: sys_socket.in.h $(LINK_WARNING_H) +sys/socket.h: sys_socket.in.h $(LINK_WARNING_H) $(ARG_NONNULL_H) $(AM_V_at)$(MKDIR_P) sys $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ @@ -51,6 +52,7 @@ -e 's|@''HAVE_SA_FAMILY_T''@|$(HAVE_SA_FAMILY_T)|g' \ -e 's|@''HAVE_ACCEPT4''@|$(HAVE_ACCEPT4)|g' \ -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ < $(srcdir)/sys_socket.in.h; \ } > $@-t && \ mv -f $@-t $@
--- a/modules/sys_stat +++ b/modules/sys_stat @@ -9,6 +9,7 @@ Depends-on: include_next link-warning +arg-nonnull time configure.ac: @@ -20,7 +21,7 @@ # We need the following in order to create <sys/stat.h> when the system # has one that is incomplete. -sys/stat.h: sys_stat.in.h $(LINK_WARNING_H) +sys/stat.h: sys_stat.in.h $(LINK_WARNING_H) $(ARG_NONNULL_H) $(AM_V_at)$(MKDIR_P) sys $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ @@ -60,6 +61,7 @@ -e 's|@''REPLACE_STAT''@|$(REPLACE_STAT)|g' \ -e 's|@''REPLACE_UTIMENSAT''@|$(REPLACE_UTIMENSAT)|g' \ -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ < $(srcdir)/sys_stat.in.h; \ } > $@-t && \ mv $@-t $@
--- a/modules/sys_time +++ b/modules/sys_time @@ -7,6 +7,7 @@ Depends-on: include_next +arg-nonnull configure.ac: gl_HEADER_SYS_TIME_H @@ -17,7 +18,7 @@ # We need the following in order to create <sys/time.h> when the system # doesn't have one that works with the given compiler. -sys/time.h: sys_time.in.h +sys/time.h: sys_time.in.h $(ARG_NONNULL_H) $(AM_V_at)$(MKDIR_P) sys $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ @@ -27,6 +28,7 @@ -e 's|@''NEXT_SYS_TIME_H''@|$(NEXT_SYS_TIME_H)|g' \ -e 's/@''REPLACE_GETTIMEOFDAY''@/$(REPLACE_GETTIMEOFDAY)/g' \ -e 's/@''HAVE_STRUCT_TIMEVAL''@/$(HAVE_STRUCT_TIMEVAL)/g' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ < $(srcdir)/sys_time.in.h; \ } > $@-t && \ mv $@-t $@
--- a/modules/sys_times +++ b/modules/sys_times @@ -7,6 +7,7 @@ Depends-on: link-warning +arg-nonnull configure.ac: gl_SYS_TIMES_H @@ -17,12 +18,13 @@ # We need the following in order to create <sys/times.h> when the system # doesn't have one that works with the given compiler. -sys/times.h: sys_times.in.h $(LINK_WARNING_H) +sys/times.h: sys_times.in.h $(LINK_WARNING_H) $(ARG_NONNULL_H) $(AM_V_at)$(MKDIR_P) sys $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ sed -e 's|@''GNULIB_TIMES''@|$(GNULIB_TIMES)|g' \ -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ < $(srcdir)/sys_times.in.h; \ } > $@-t && \ mv $@-t $@
--- a/modules/sys_utsname +++ b/modules/sys_utsname @@ -7,6 +7,7 @@ Depends-on: link-warning +arg-nonnull configure.ac: gl_SYS_UTSNAME_H @@ -17,13 +18,14 @@ # We need the following in order to create <sys/utsname.h> when the system # does not have one. -sys/utsname.h: sys_utsname.in.h $(LINK_WARNING_H) +sys/utsname.h: sys_utsname.in.h $(LINK_WARNING_H) $(ARG_NONNULL_H) $(AM_V_at)$(MKDIR_P) sys $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ sed -e 's|@''GNULIB_UNAME''@|$(GNULIB_UNAME)|g' \ -e 's|@''HAVE_UNAME''@|$(HAVE_UNAME)|g' \ -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ < $(srcdir)/sys_utsname.in.h; \ } > $@-t && \ mv $@-t $@
--- a/modules/time +++ b/modules/time @@ -8,6 +8,7 @@ Depends-on: extensions include_next +arg-nonnull stddef configure.ac: @@ -18,7 +19,7 @@ # We need the following in order to create <time.h> when the system # doesn't have one that works with the given compiler. -time.h: time.in.h +time.h: time.in.h $(ARG_NONNULL_H) $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ @@ -31,6 +32,7 @@ -e 's|@REPLACE_TIMEGM''@|$(REPLACE_TIMEGM)|g' \ -e 's|@SYS_TIME_H_DEFINES_STRUCT_TIMESPEC''@|$(SYS_TIME_H_DEFINES_STRUCT_TIMESPEC)|g' \ -e 's|@TIME_H_DEFINES_STRUCT_TIMESPEC''@|$(TIME_H_DEFINES_STRUCT_TIMESPEC)|g' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ < $(srcdir)/time.in.h; \ } > $@-t && \ mv $@-t $@
--- a/modules/unistd +++ b/modules/unistd @@ -8,6 +8,7 @@ Depends-on: include_next link-warning +arg-nonnull stddef configure.ac: @@ -18,7 +19,7 @@ # We need the following in order to create an empty placeholder for # <unistd.h> when the system doesn't have one. -unistd.h: unistd.in.h $(LINK_WARNING_H) +unistd.h: unistd.in.h $(LINK_WARNING_H) $(ARG_NONNULL_H) $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ sed -e 's|@''HAVE_UNISTD_H''@|$(HAVE_UNISTD_H)|g' \ @@ -117,6 +118,7 @@ -e 's|@''UNISTD_H_HAVE_WINSOCK2_H''@|$(UNISTD_H_HAVE_WINSOCK2_H)|g' \ -e 's|@''UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS''@|$(UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS)|g' \ -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ < $(srcdir)/unistd.in.h; \ } > $@-t && \ mv $@-t $@
--- a/modules/wchar +++ b/modules/wchar @@ -9,6 +9,7 @@ Depends-on: include_next link-warning +arg-nonnull stddef configure.ac: @@ -19,7 +20,7 @@ # We need the following in order to create <wchar.h> when the system # version does not work standalone. -wchar.h: wchar.in.h $(LINK_WARNING_H) +wchar.h: wchar.in.h $(LINK_WARNING_H) $(ARG_NONNULL_H) $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ @@ -62,6 +63,7 @@ -e 's|@''REPLACE_WCSNRTOMBS''@|$(REPLACE_WCSNRTOMBS)|g' \ -e 's|@''REPLACE_WCWIDTH''@|$(REPLACE_WCWIDTH)|g' \ -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ < $(srcdir)/wchar.in.h; \ } > $@-t && \ mv $@-t $@
--- a/tests/test-canonicalize-lgpl.c +++ b/tests/test-canonicalize-lgpl.c @@ -43,6 +43,12 @@ #define BASE "t-can-lgpl.tmp" +static void * +null_ptr (void) +{ + return NULL; +} + int main (void) { @@ -75,7 +81,7 @@ ASSERT (result == NULL); ASSERT (errno == ENOENT); errno = 0; - result = canonicalize_file_name (NULL); + result = canonicalize_file_name (null_ptr ()); ASSERT (result == NULL); ASSERT (errno == EINVAL); }
--- a/tests/test-canonicalize.c +++ b/tests/test-canonicalize.c @@ -44,6 +44,12 @@ #define BASE "t-can.tmp" +static void * +null_ptr (void) +{ + return NULL; +} + int main (void) { @@ -79,7 +85,7 @@ ASSERT (result2 == NULL); ASSERT (errno == ENOENT); errno = 0; - result1 = canonicalize_file_name (NULL); + result1 = canonicalize_file_name (null_ptr ()); ASSERT (result1 == NULL); ASSERT (errno == EINVAL); errno = 0;
--- a/tests/test-memmem.c +++ b/tests/test-memmem.c @@ -38,6 +38,12 @@ } \ while (0) +static void * +null_ptr (void) +{ + return NULL; +} + int main (int argc, char *argv[]) { @@ -88,7 +94,7 @@ { const char input[] = "foo"; - const char *result = memmem (input, strlen (input), NULL, 0); + const char *result = memmem (input, strlen (input), null_ptr (), 0); ASSERT (result == input); }