Add more __restricts, clean up __format__ attributes.

Change-Id: I7e2d270cc722d339d221eaea92747eaff3b51403
This commit is contained in:
Elliott Hughes 2013-05-14 16:08:43 -07:00
parent 349ef893e8
commit d04c183979
5 changed files with 93 additions and 101 deletions

View File

@ -48,42 +48,42 @@
__BEGIN_DECLS __BEGIN_DECLS
__noreturn void err(int, const char *, ...) __noreturn void err(int, const char *, ...)
__attribute__((__format__ (printf, 2, 3))); __printflike(2, 3);
__noreturn void verr(int, const char *, __va_list) __noreturn void verr(int, const char *, __va_list)
__attribute__((__format__ (printf, 2, 0))); __printflike(2, 0);
__noreturn void errx(int, const char *, ...) __noreturn void errx(int, const char *, ...)
__attribute__((__format__ (printf, 2, 3))); __printflike(2, 3);
__noreturn void verrx(int, const char *, __va_list) __noreturn void verrx(int, const char *, __va_list)
__attribute__((__format__ (printf, 2, 0))); __printflike(2, 0);
void warn(const char *, ...) void warn(const char *, ...)
__attribute__((__format__ (printf, 1, 2))); __printflike(1, 2);
void vwarn(const char *, __va_list) void vwarn(const char *, __va_list)
__attribute__((__format__ (printf, 1, 0))); __printflike(1, 0);
void warnx(const char *, ...) void warnx(const char *, ...)
__attribute__((__format__ (printf, 1, 2))); __printflike(1, 2);
void vwarnx(const char *, __va_list) void vwarnx(const char *, __va_list)
__attribute__((__format__ (printf, 1, 0))); __printflike(1, 0);
/* /*
* The _* versions are for use in library functions so user-defined * The _* versions are for use in library functions so user-defined
* versions of err*,warn* do not get used. * versions of err*,warn* do not get used.
*/ */
__noreturn void _err(int, const char *, ...) __noreturn void _err(int, const char *, ...)
__attribute__((__format__ (printf, 2, 3))); __printflike(2, 3);
__noreturn void _verr(int, const char *, __va_list) __noreturn void _verr(int, const char *, __va_list)
__attribute__((__format__ (printf, 2, 0))); __printflike(2, 0);
__noreturn void _errx(int, const char *, ...) __noreturn void _errx(int, const char *, ...)
__attribute__((__format__ (printf, 2, 3))); __printflike(2, 3);
__noreturn void _verrx(int, const char *, __va_list) __noreturn void _verrx(int, const char *, __va_list)
__attribute__((__format__ (printf, 2, 0))); __printflike(2, 0);
void _warn(const char *, ...) void _warn(const char *, ...)
__attribute__((__format__ (printf, 1, 2))); __printflike(1, 2);
void _vwarn(const char *, __va_list) void _vwarn(const char *, __va_list)
__attribute__((__format__ (printf, 1, 0))); __printflike(1, 0);
void _warnx(const char *, ...) void _warnx(const char *, ...)
__attribute__((__format__ (printf, 1, 2))); __printflike(1, 2);
void _vwarnx(const char *, __va_list) void _vwarnx(const char *, __va_list)
__attribute__((__format__ (printf, 1, 0))); __printflike(1, 0);
__END_DECLS __END_DECLS

View File

@ -139,8 +139,8 @@ __END_DECLS
#define __SMBF 0x0080 /* _buf is from malloc */ #define __SMBF 0x0080 /* _buf is from malloc */
#define __SAPP 0x0100 /* fdopen()ed in append mode */ #define __SAPP 0x0100 /* fdopen()ed in append mode */
#define __SSTR 0x0200 /* this is an sprintf/snprintf string */ #define __SSTR 0x0200 /* this is an sprintf/snprintf string */
#define __SOPT 0x0400 /* do fseek() optimisation */ #define __SOPT 0x0400 /* do fseek() optimization */
#define __SNPT 0x0800 /* do not do fseek() optimisation */ #define __SNPT 0x0800 /* do not do fseek() optimization */
#define __SOFF 0x1000 /* set iff _offset is in fact correct */ #define __SOFF 0x1000 /* set iff _offset is in fact correct */
#define __SMOD 0x2000 /* true => fgetln modified _p text */ #define __SMOD 0x2000 /* true => fgetln modified _p text */
#define __SALC 0x4000 /* allocate string space dynamically */ #define __SALC 0x4000 /* allocate string space dynamically */
@ -160,14 +160,14 @@ __END_DECLS
#define _IONBF 2 /* setvbuf should set unbuffered */ #define _IONBF 2 /* setvbuf should set unbuffered */
#define BUFSIZ 1024 /* size of buffer used by setbuf */ #define BUFSIZ 1024 /* size of buffer used by setbuf */
#define EOF (-1) #define EOF (-1)
/* /*
* FOPEN_MAX is a minimum maximum, and should be the number of descriptors * FOPEN_MAX is a minimum maximum, and is the number of streams that
* that the kernel can provide without allocation of a resource that can * stdio can provide without attempting to allocate further resources
* fail without the process sleeping. Do not use this for anything. * (which could fail). Do not use this for anything.
*/ */
#define FOPEN_MAX 20 /* must be <= OPEN_MAX <sys/syslimits.h> */ #define FOPEN_MAX 20 /* must be <= OPEN_MAX <sys/syslimits.h> */
#define FILENAME_MAX 1024 /* must be <= PATH_MAX <sys/syslimits.h> */ #define FILENAME_MAX 1024 /* must be <= PATH_MAX <sys/syslimits.h> */
@ -178,6 +178,7 @@ __END_DECLS
#define L_tmpnam 1024 /* XXX must be == PATH_MAX */ #define L_tmpnam 1024 /* XXX must be == PATH_MAX */
#define TMP_MAX 308915776 #define TMP_MAX 308915776
/* Always ensure that these are consistent with <fcntl.h> and <unistd.h>! */
#ifndef SEEK_SET #ifndef SEEK_SET
#define SEEK_SET 0 /* set file offset to offset */ #define SEEK_SET 0 /* set file offset to offset */
#endif #endif
@ -202,25 +203,20 @@ int feof(FILE *);
int ferror(FILE *); int ferror(FILE *);
int fflush(FILE *); int fflush(FILE *);
int fgetc(FILE *); int fgetc(FILE *);
int fgetpos(FILE *, fpos_t *); char *fgets(char * __restrict, int, FILE * __restrict);
char *fgets(char *, int, FILE *); FILE *fopen(const char * __restrict , const char * __restrict);
FILE *fopen(const char *, const char *); int fprintf(FILE * __restrict , const char * __restrict, ...)
int fprintf(FILE *, const char *, ...) __printflike(2, 3);
__attribute__((__format__ (printf, 2, 3)))
__attribute__((__nonnull__ (2)));
int fputc(int, FILE *); int fputc(int, FILE *);
int fputs(const char *, FILE *); int fputs(const char * __restrict, FILE * __restrict);
size_t fread(void *, size_t, size_t, FILE *); size_t fread(void * __restrict, size_t, size_t, FILE * __restrict);
FILE *freopen(const char *, const char *, FILE *); FILE *freopen(const char * __restrict, const char * __restrict,
int fscanf(FILE *, const char *, ...) FILE * __restrict);
__attribute__ ((__format__ (scanf, 2, 3))) int fscanf(FILE * __restrict, const char * __restrict, ...)
__attribute__ ((__nonnull__ (2))); __scanflike(2, 3);
int fseek(FILE *, long, int); int fseek(FILE *, long, int);
int fseeko(FILE *, off_t, int);
int fsetpos(FILE *, const fpos_t *);
long ftell(FILE *); long ftell(FILE *);
off_t ftello(FILE *); size_t fwrite(const void * __restrict, size_t, size_t, FILE * __restrict);
size_t fwrite(const void *, size_t, size_t, FILE *);
int getc(FILE *); int getc(FILE *);
int getchar(void); int getchar(void);
ssize_t getdelim(char ** __restrict, size_t * __restrict, int, ssize_t getdelim(char ** __restrict, size_t * __restrict, int,
@ -234,55 +230,55 @@ extern int sys_nerr; /* perror(3) external variables */
extern char *sys_errlist[]; extern char *sys_errlist[];
#endif #endif
void perror(const char *); void perror(const char *);
int printf(const char *, ...) int printf(const char * __restrict, ...)
__attribute__((__format__ (printf, 1, 2))) __printflike(1, 2);
__attribute__((__nonnull__ (1)));
int putc(int, FILE *); int putc(int, FILE *);
int putchar(int); int putchar(int);
int puts(const char *); int puts(const char *);
int remove(const char *); int remove(const char *);
int rename(const char *, const char *);
void rewind(FILE *); void rewind(FILE *);
int scanf(const char *, ...) int scanf(const char * __restrict, ...)
__attribute__ ((__format__ (scanf, 1, 2))) __scanflike(1, 2);
__attribute__ ((__nonnull__ (1))); void setbuf(FILE * __restrict, char * __restrict);
void setbuf(FILE *, char *); int setvbuf(FILE * __restrict, char * __restrict, int, size_t);
int setvbuf(FILE *, char *, int, size_t); int sscanf(const char * __restrict, const char * __restrict, ...)
int sprintf(char *, const char *, ...) __scanflike(2, 3);
__attribute__((__format__ (printf, 2, 3)))
__attribute__((__nonnull__ (2)));
int sscanf(const char *, const char *, ...)
__attribute__ ((__format__ (scanf, 2, 3)))
__attribute__ ((__nonnull__ (2)));
FILE *tmpfile(void); FILE *tmpfile(void);
char *tmpnam(char *);
int ungetc(int, FILE *); int ungetc(int, FILE *);
int vfprintf(FILE *, const char *, __va_list) int vfprintf(FILE * __restrict, const char * __restrict, __va_list)
__attribute__((__format__ (printf, 2, 0))) __printflike(2, 0);
__attribute__((__nonnull__ (2))); int vprintf(const char * __restrict, __va_list)
int vprintf(const char *, __va_list) __printflike(1, 0);
__attribute__((__format__ (printf, 1, 0)))
__attribute__((__nonnull__ (1))); #ifndef __AUDIT__
int vsprintf(char *, const char *, __va_list) char *gets(char *);
__attribute__((__format__ (printf, 2, 0))) int sprintf(char * __restrict, const char * __restrict, ...)
__attribute__((__nonnull__ (2))); __printflike(2, 3);
char *tmpnam(char *);
int vsprintf(char * __restrict, const char * __restrict,
__va_list)
__printflike(2, 0);
#endif
int rename (const char *, const char *);
int fgetpos(FILE * __restrict, fpos_t * __restrict);
int fsetpos(FILE *, const fpos_t *);
int fseeko(FILE *, off_t, int);
off_t ftello(FILE *);
#if __ISO_C_VISIBLE >= 1999 || __BSD_VISIBLE #if __ISO_C_VISIBLE >= 1999 || __BSD_VISIBLE
int snprintf(char *, size_t, const char *, ...) int snprintf(char * __restrict, size_t, const char * __restrict, ...)
__attribute__((__format__ (printf, 3, 4))) __printflike(3, 4);
__attribute__((__nonnull__ (3))); int vfscanf(FILE * __restrict, const char * __restrict, __va_list)
int vfscanf(FILE *, const char *, __va_list) __scanflike(2, 0);
__attribute__((__format__ (scanf, 2, 0)))
__attribute__((__nonnull__ (2)));
int vscanf(const char *, __va_list) int vscanf(const char *, __va_list)
__attribute__((__format__ (scanf, 1, 0))) __scanflike(1, 0);
__attribute__((__nonnull__ (1))); int vsnprintf(char * __restrict, size_t, const char * __restrict, __va_list)
int vsnprintf(char *, size_t, const char *, __va_list) __printflike(3, 0);
__attribute__((__format__ (printf, 3, 0))) int vsscanf(const char * __restrict, const char * __restrict, __va_list)
__attribute__((__nonnull__ (3))); __scanflike(2, 0);
int vsscanf(const char *, const char *, __va_list)
__attribute__((__format__ (scanf, 2, 0)))
__attribute__((__nonnull__ (2)));
#endif /* __ISO_C_VISIBLE >= 1999 || __BSD_VISIBLE */ #endif /* __ISO_C_VISIBLE >= 1999 || __BSD_VISIBLE */
__END_DECLS __END_DECLS
@ -335,18 +331,17 @@ __END_DECLS
*/ */
#if __BSD_VISIBLE #if __BSD_VISIBLE
__BEGIN_DECLS __BEGIN_DECLS
int asprintf(char **, const char *, ...) int asprintf(char ** __restrict, const char * __restrict, ...)
__attribute__((__format__ (printf, 2, 3))) __printflike(2, 3);
__attribute__((__nonnull__ (2))); char *fgetln(FILE * __restrict, size_t * __restrict);
char *fgetln(FILE *, size_t *);
int fpurge(FILE *); int fpurge(FILE *);
int getw(FILE *); int getw(FILE *);
int putw(int, FILE *); int putw(int, FILE *);
void setbuffer(FILE *, char *, int); void setbuffer(FILE *, char *, int);
int setlinebuf(FILE *); int setlinebuf(FILE *);
int vasprintf(char **, const char *, __va_list) int vasprintf(char ** __restrict, const char * __restrict,
__attribute__((__format__ (printf, 2, 0))) __va_list)
__attribute__((__nonnull__ (2))); __printflike(2, 0);
__END_DECLS __END_DECLS
/* /*
@ -449,11 +444,9 @@ extern int __isthreaded;
*/ */
__BEGIN_DECLS __BEGIN_DECLS
int fdprintf(int, const char*, ...) int fdprintf(int, const char*, ...)
__attribute__((__format__ (printf, 2, 3))) __printflike(2, 3);
__attribute__((__nonnull__ (2)));
int vfdprintf(int, const char*, __va_list) int vfdprintf(int, const char*, __va_list)
__attribute__((__format__ (printf, 2, 0))) __printflike(2, 0);
__attribute__((__nonnull__ (2)));
__END_DECLS __END_DECLS
#endif /* _GNU_SOURCE */ #endif /* _GNU_SOURCE */
@ -462,24 +455,21 @@ __END_DECLS
__BEGIN_DECLS __BEGIN_DECLS
__BIONIC_FORTIFY_INLINE __BIONIC_FORTIFY_INLINE
__attribute__((__format__ (printf, 3, 0))) __printflike(3, 0)
__attribute__((__nonnull__ (3)))
int vsnprintf(char *dest, size_t size, const char *format, __va_list ap) int vsnprintf(char *dest, size_t size, const char *format, __va_list ap)
{ {
return __builtin___vsnprintf_chk(dest, size, 0, __bos(dest), format, ap); return __builtin___vsnprintf_chk(dest, size, 0, __bos(dest), format, ap);
} }
__BIONIC_FORTIFY_INLINE __BIONIC_FORTIFY_INLINE
__attribute__((__format__ (printf, 2, 0))) __printflike(2, 0)
__attribute__((__nonnull__ (2)))
int vsprintf(char *dest, const char *format, __va_list ap) int vsprintf(char *dest, const char *format, __va_list ap)
{ {
return __builtin___vsprintf_chk(dest, 0, __bos(dest), format, ap); return __builtin___vsprintf_chk(dest, 0, __bos(dest), format, ap);
} }
__BIONIC_FORTIFY_INLINE __BIONIC_FORTIFY_INLINE
__attribute__((__format__ (printf, 3, 4))) __printflike(3, 4)
__attribute__((__nonnull__ (3)))
int snprintf(char *str, size_t size, const char *format, ...) int snprintf(char *str, size_t size, const char *format, ...)
{ {
return __builtin___snprintf_chk(str, size, 0, return __builtin___snprintf_chk(str, size, 0,
@ -487,8 +477,7 @@ int snprintf(char *str, size_t size, const char *format, ...)
} }
__BIONIC_FORTIFY_INLINE __BIONIC_FORTIFY_INLINE
__attribute__((__format__ (printf, 2, 3))) __printflike(2, 3)
__attribute__((__nonnull__ (2)))
int sprintf(char *dest, const char *format, ...) int sprintf(char *dest, const char *format, ...)
{ {
return __builtin___sprintf_chk(dest, 0, return __builtin___sprintf_chk(dest, 0,

View File

@ -211,6 +211,9 @@
#define __statement(x) (x) #define __statement(x) (x)
#endif #endif
#define __printflike(x, y) __attribute__((__format__(printf, x, y))) __attribute__((__nonnull__(x)))
#define __scanflike(x, y) __attribute__((__format__(scanf, x, y))) __attribute__((__nonnull__(x)))
/* /*
* C99 defines the restrict type qualifier keyword, which was made available * C99 defines the restrict type qualifier keyword, which was made available
* in GCC 2.92. * in GCC 2.92.

View File

@ -79,7 +79,7 @@ __LIBC_HIDDEN__ void __libc_set_abort_message(const char* msg);
// //
__LIBC_HIDDEN__ __noreturn void __libc_fatal(const char* format, ...) __LIBC_HIDDEN__ __noreturn void __libc_fatal(const char* format, ...)
__attribute__((__format__(printf, 1, 2))); __printflike(1, 2);
// //
// Formatting routines for the C library's internal debugging. // Formatting routines for the C library's internal debugging.
@ -87,13 +87,13 @@ __LIBC_HIDDEN__ __noreturn void __libc_fatal(const char* format, ...)
// //
__LIBC_HIDDEN__ int __libc_format_buffer(char* buffer, size_t buffer_size, const char* format, ...) __LIBC_HIDDEN__ int __libc_format_buffer(char* buffer, size_t buffer_size, const char* format, ...)
__attribute__((__format__(printf, 3, 4))); __printflike(3, 4);
__LIBC_HIDDEN__ int __libc_format_fd(int fd, const char* format, ...) __LIBC_HIDDEN__ int __libc_format_fd(int fd, const char* format, ...)
__attribute__((__format__(printf, 2, 3))); __printflike(2, 3);
__LIBC_HIDDEN__ int __libc_format_log(int priority, const char* tag, const char* format, ...) __LIBC_HIDDEN__ int __libc_format_log(int priority, const char* tag, const char* format, ...)
__attribute__((__format__(printf, 3, 4))); __printflike(3, 4);
__LIBC_HIDDEN__ int __libc_format_log_va_list(int priority, const char* tag, const char* format, __LIBC_HIDDEN__ int __libc_format_log_va_list(int priority, const char* tag, const char* format,
va_list ap); va_list ap);

View File

@ -21,7 +21,7 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
#include <arpa_nameser.h> #include <arpa_nameser.h>
#define ISC_FORMAT_PRINTF(a,b) __attribute__((__format__(__printf__,a,b))) #define ISC_FORMAT_PRINTF(a,b) __printflike(a,b)
#define ISC_SOCKLEN_T socklen_t #define ISC_SOCKLEN_T socklen_t
#endif #endif