Added macros __printflike() and __scanflike() to <sys/cdefs.h>.

Use them to `make gcc -Wformat' check formats for all printf-like
and scanf-like functions in /usr/src except for the err()/warn()
family.  err() isn't quite printf-like since its format arg can
legitimately be NULL.  syslog() isn't quite printf-like, but gcc
already accepts %m, even for plain printf() when it shouldn't.
This commit is contained in:
Bruce Evans 1998-07-13 06:45:23 +00:00
parent eaaeb9f30c
commit 748993b899
7 changed files with 43 additions and 30 deletions

View File

@ -34,7 +34,7 @@
* SUCH DAMAGE.
*
* @(#)stdio.h 8.5 (Berkeley) 4/29/95
* $Id: stdio.h,v 1.18 1998/06/14 16:04:20 bde Exp $
* $Id: stdio.h,v 1.19 1998/07/08 00:52:40 peter Exp $
*/
#ifndef _STDIO_H_
@ -293,7 +293,7 @@ __END_DECLS
*/
#if !defined (_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
__BEGIN_DECLS
int asprintf __P((char **, const char *, ...));
int asprintf __P((char **, const char *, ...)) __printflike(2, 3);
char *fgetln __P((FILE *, size_t *));
int fpurge __P((FILE *));
int getw __P((FILE *));
@ -303,11 +303,14 @@ int putw __P((int, FILE *));
void setbuffer __P((FILE *, char *, int));
int setlinebuf __P((FILE *));
char *tempnam __P((const char *, const char *));
int snprintf __P((char *, size_t, const char *, ...));
int vasprintf __P((char **, const char *, _BSD_VA_LIST_));
int vsnprintf __P((char *, size_t, const char *, _BSD_VA_LIST_));
int vscanf __P((const char *, _BSD_VA_LIST_));
int vsscanf __P((const char *, const char *, _BSD_VA_LIST_));
int snprintf __P((char *, size_t, const char *, ...)) __printflike(3, 4);
int vasprintf __P((char **, const char *, _BSD_VA_LIST_))
__printflike(2, 0);
int vsnprintf __P((char *, size_t, const char *, _BSD_VA_LIST_))
__printflike(3, 0);
int vscanf __P((const char *, _BSD_VA_LIST_)) __scanflike(1, 0);
int vsscanf __P((const char *, const char *, _BSD_VA_LIST_))
__scanflike(2, 0);
__END_DECLS
/*

View File

@ -27,7 +27,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: ddb.h,v 1.18 1998/06/07 17:09:38 dfr Exp $
* $Id: ddb.h,v 1.19 1998/07/08 09:11:40 bde Exp $
*/
/*
@ -85,12 +85,12 @@ db_addr_t db_disasm __P((db_addr_t loc, boolean_t altfmt));
void db_error __P((char *s));
int db_expression __P((db_expr_t *valuep));
int db_get_variable __P((db_expr_t *valuep));
void db_iprintf __P((const char *,...));
void db_iprintf __P((const char *,...)) __printflike(1, 2);
struct vm_map *db_map_addr __P((vm_offset_t));
boolean_t db_map_current __P((struct vm_map *));
boolean_t db_map_equal __P((struct vm_map *, struct vm_map *));
void db_print_loc_and_inst __P((db_addr_t loc));
void db_printf __P((const char *fmt, ...));
void db_printf __P((const char *fmt, ...)) __printflike(1, 2);
void db_read_bytes __P((vm_offset_t addr, size_t size, char *data));
/* machine-dependent */
int db_readline __P((char *lstart, int lsize));
@ -104,7 +104,6 @@ int db_value_of_name __P((char *name, db_expr_t *valuep));
void db_write_bytes __P((vm_offset_t addr, size_t size, char *data));
/* machine-dependent */
void kdb_init __P((void));
void kdbprintf __P((const char *fmt, ...));
db_cmdfcn_t db_breakpoint_cmd;
db_cmdfcn_t db_continue_cmd;

View File

@ -34,7 +34,7 @@
* SUCH DAMAGE.
*
* @(#)cdefs.h 8.8 (Berkeley) 1/9/95
* $Id: cdefs.h,v 1.17 1998/06/14 13:40:01 bde Exp $
* $Id: cdefs.h,v 1.18 1998/06/18 18:35:04 peter Exp $
*/
#ifndef _SYS_CDEFS_H_
@ -142,6 +142,16 @@
#define __unused __attribute__((__unused__))
#endif
#if __GNUC__ < 2 || __GNUC__ == 2 && __GNUC_MINOR__ < 7
#define __printflike(fmtarg, firstvararg)
#define __scanflike(fmtarg, firstvararg)
#else
#define __printflike(fmtarg, firstvararg) \
__attribute__((__format__ (__printf__, fmtarg, firstvararg)))
#define __scanflike(fmtarg, firstvararg) \
__attribute__((__format__ (__scanf__, fmtarg, firstvararg)))
#endif
#ifdef __GNUC__
#ifdef __ELF__
#ifdef __STDC__

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: devfsext.h,v 1.19 1998/04/20 04:55:17 julian Exp $
* $Id: devfsext.h,v 1.20 1998/04/28 00:10:52 julian Exp $
*/
#ifndef _SYS_DEVFSEXT_H_
@ -35,14 +35,15 @@
* and the initial default perms/ownerships.
*/
void *devfs_add_devswf __P((void *devsw, int minor, int chrblk, uid_t uid,
gid_t gid, int perms, char *fmt, ...));
gid_t gid, int perms, char *fmt, ...))
__printflike(7, 8);
/*
* Make a link to a device you already made, and have the cookie for
* We get another cookie, but for now, it can be discarded, as
* at the moment there is nothing you can do with it that you couldn't do
* with the original cookie. ( XXX this might be something I should change )
*/
void *devfs_link __P((void *original, char *fmt, ...));
void *devfs_link __P((void *original, char *fmt, ...)) __printflike(2, 3);
/*
* Remove all instances of a device you have made. INCLUDING LINKS.

View File

@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* @(#)syslog.h 8.1 (Berkeley) 6/2/93
* $Id: syslog.h,v 1.14 1997/10/06 18:20:23 joerg Exp $
* $Id: syslog.h,v 1.15 1997/10/06 20:37:01 joerg Exp $
*/
#ifndef _SYS_SYSLOG_H_
@ -192,8 +192,8 @@ __BEGIN_DECLS
void closelog __P((void));
void openlog __P((const char *, int, int));
int setlogmask __P((int));
void syslog __P((int, const char *, ...));
void vsyslog __P((int, const char *, _BSD_VA_LIST_));
void syslog __P((int, const char *, ...)) __printflike(2, 3);
void vsyslog __P((int, const char *, _BSD_VA_LIST_)) __printflike(2, 0);
__END_DECLS
#endif /* !KERNEL */

View File

@ -36,7 +36,7 @@
* SUCH DAMAGE.
*
* @(#)systm.h 8.7 (Berkeley) 3/29/95
* $Id: systm.h,v 1.71 1998/06/07 17:13:04 dfr Exp $
* $Id: systm.h,v 1.72 1998/06/09 12:52:35 bde Exp $
*/
#ifndef _SYS_SYSTM_H_
@ -96,21 +96,21 @@ int ureadc __P((int, struct uio *));
void *hashinit __P((int count, struct malloc_type *type, u_long *hashmask));
void *phashinit __P((int count, struct malloc_type *type, u_long *nentries));
void panic __P((const char *, ...)) __dead2;
void panic __P((const char *, ...)) __dead2 __printflike(1, 2);
void cpu_boot __P((int));
void cpu_rootconf __P((void));
void cpu_dumpconf __P((void));
void tablefull __P((const char *));
int addlog __P((const char *, ...));
int addlog __P((const char *, ...)) __printflike(1, 2);
int kvprintf __P((char const *, void (*)(int, void*), void *, int,
_BSD_VA_LIST_));
void log __P((int, const char *, ...));
_BSD_VA_LIST_)) __printflike(1, 0);
void log __P((int, const char *, ...)) __printflike(2, 3);
void logwakeup __P((void));
int printf __P((const char *, ...));
int sprintf __P((char *buf, const char *, ...));
void uprintf __P((const char *, ...));
void vprintf __P((const char *, _BSD_VA_LIST_));
void ttyprintf __P((struct tty *, const char *, ...));
int printf __P((const char *, ...)) __printflike(1, 2);
int sprintf __P((char *buf, const char *, ...)) __printflike(2, 3);
void uprintf __P((const char *, ...)) __printflike(1, 2);
void vprintf __P((const char *, _BSD_VA_LIST_)) __printflike(1, 0);
void ttyprintf __P((struct tty *, const char *, ...)) __printflike(2, 3);
void bcopy __P((const void *from, void *to, size_t len));
void ovbcopy __P((const void *from, void *to, size_t len));

View File

@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* @(#)tprintf.h 8.1 (Berkeley) 6/2/93
* $Id: tprintf.h,v 1.5 1997/02/22 09:46:12 peter Exp $
* $Id: tprintf.h,v 1.6 1998/02/03 21:51:58 bde Exp $
*/
#ifndef _SYS_TPRINTF_H_
@ -44,6 +44,6 @@ struct proc;
tpr_t tprintf_open __P((struct proc *));
void tprintf_close __P((tpr_t));
void tprintf __P((tpr_t, const char *fmt, ...));
void tprintf __P((tpr_t, const char *fmt, ...)) __printflike(2, 3);
#endif