add gcc printf format checks
PATCH 1/1 add gcc printf format checks
[PATCH] add gcc printf format checks
trivial patch which adds some missing printf format checking to compat.h and msdos_fs.h
Build-tested and no regressions found.
include/linux/compat.h +1 -1
@@ -232,7 +232,7 @@ extern int put_compat_itimerspec(struct compat_itimerspec __user *dst,asmlinkage long compat_sys_adjtimex (struct compat_timex __user *utp); -extern int compat_printk (const char *fmt, ...); +extern int compat_printk(const char *fmt, ...) __printf(1,2);extern void sigset_from_compat (sigset_t *set,compat_sigset_t *compat); asmlinkage long compat_sys_migrate_pages(compat_pid_t pid,
include/linux/msdos_fs.h +1 -1
@@ -419,7 +419,7 @@ extern int fat_fill_super(struct super_block *sb, void *data, int silent,extern int fat_flush_inodes (struct super_block *sb,struct inode *i1,struct inode *i2);/* fat/misc.c */ -extern void fat_fs_panic (struct super_block *s,const char *fmt, ...); +extern void fat_fs_panic(struct super_block *s, const char *fmt, ...) __printf(2,3);extern void fat_clusters_flush (struct super_block *sb);extern int fat_chain_add (struct inode *inode,int new_dclus,int nr_cluster);extern int date_dos2unix (unsigned short time,unsigned short date);
include/linux/compat.h extern int put_compat_itimerspec(struct compat_itimerspec __user *dst, · line 235
Quoted 11 lines · Helge Deller
[PATCH] add gcc printf format checks
include/linux/compat.h +1
-1@@ -232,7 +232,7 @@ extern int put_compat_itimerspec(struct compat_itimerspec __user *dst,asmlinkage long compat_sys_adjtimex (struct compat_timex __user *utp); -extern int compat_printk (const char *fmt, ...); +extern int compat_printk(const char *fmt, ...) __printf(1,2);
__attribute__((format(printf, 1, 2))) seems to be the preferred form. 91 to 1.
I think __printf should be removed from gcc-compiler.h and the only use in include/linux/marker.h converted.
A message that is not in the archive (sent off-list or not yet received): [email protected]
Mathieu Desnoyers
Acked-byQuoted 39 lines · * Helge Deller ([email protected]) wrote:
Quoted 5 lines · Joe Perches
__attribute__((format(printf, 1, 2)))seems to be the preferred form. 91 to 1.I think
__printfshould be removed fromgcc-compiler.hand the only use ininclude/linux/marker.hconverted.Personally I would prefer to convert every user over to the smaller
__printf()version. Nevertheless, below is an updated patch which does what you propose.=======================================
[PATCH] add gcc printf format checks and drop
__printf()defineTrivial patch which adds some missing printf format checking to
compat.handmsdos_fs.h. Additionally, it converts the one and only user of the__printfmacro to__attribute__(printf).Signed-off-by Helge Deller <[email protected]>include/linux/compiler-gcc.h +0
-1@@ -49,7 +49,6 @@*/ #define __pure __attribute__((pure))#define __aligned (x) __attribute__((aligned(x))) -#define __printf (a,b) __attribute__((format(printf,a,b)))#define noinline __attribute__((noinline))#define __attribute_const__ __attribute__((__const__))#define __maybe_unused __attribute__((unused))include/linux/marker.h +0
-0
include/linux/marker.h static inline void marker_update_probe_range(struct marker *begin, · line 104
Quoted 6 lines
include/linux/marker.h +2
-1@@ -100,7 +100,8 @@ static inline void marker_update_probe_range(struct marker *begin,#define MARK_NOARGS " "/* To be used for string format validity checking with gcc */ -static inline void __printf(1, 2) __mark_check_format(const char *fmt, ...) +static inline void __attribute__((format (printf,1 ,2 ))) +__mark_check_format (const char *fmt, ...)
If the markers are the only user of this macro, it makes sense to change them and remove the macro. I have no strong opinion about this, but it is technically ok.
Quoted 31 lines
include/linux/marker.h +0
-0{ }include/linux/compat.h +1
-1@@ -232,7 +232,7 @@ extern int put_compat_itimerspec(struct compat_itimerspec __user *dst,asmlinkage long compat_sys_adjtimex (struct compat_timex __user *utp); -extern int compat_printk (const char *fmt, ...); +extern int compat_printk (const char *fmt, ...) __attribute__ ((format (printf,1 ,2 )));extern void sigset_from_compat (sigset_t *set,compat_sigset_t *compat); asmlinkage long compat_sys_migrate_pages(compat_pid_t pid,include/linux/msdos_fs.h +2
-1@@ -419,7 +419,8 @@ extern int fat_fill_super(struct super_block *sb, void *data, int silent,extern int fat_flush_inodes (struct super_block *sb,struct inode *i1,struct inode *i2);/* fat/misc.c */ -extern void fat_fs_panic (struct super_block *s,const char *fmt, ...); +extern void fat_fs_panic (struct super_block *s,const char *fmt, ...) + __attribute__ ((format (printf,2 ,3 )));extern void fat_clusters_flush (struct super_block *sb);extern int fat_chain_add (struct inode *inode,int new_dclus,int nr_cluster);extern int date_dos2unix (unsigned short time,unsigned short date);
Signature · 3 lines
Mathieu Desnoyers Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F BA06 3F25 A8FE 3BAE 9A68