add function attributes to sprintf() and snprintf()

Message ID 20011107172401.I14594@arthur.ubicom.tudelft.nl
State New, archived
Headers show
Series
  • add function attributes to sprintf() and snprintf()
Related show

Commit Message

Erik Mouw Nov. 7, 2001, 4:24 p.m. UTC
Hi,

This patch adds function attributes to sprintf() and snprintf() so the
compiler can catch formatting errors at compile time. Patch is against
2.4.13-ac8, but it should apply cleanly against 2.4.14 as well.


Erik

Comments

James Antill Nov. 9, 2001, 5:24 a.m. UTC | #1
Erik Mouw <J.A.K.Mouw@its.tudelft.nl> writes:

> Hi,
> 
> This patch adds function attributes to sprintf() and snprintf() so the
> compiler can catch formatting errors at compile time. Patch is against
> 2.4.13-ac8, but it should apply cleanly against 2.4.14 as well.

 This is done inside gcc as sprintf/snprintf/vsnprintf etc. are all
standard symbols so gcc automatically adds the attributes for them.

 In gcc 3.x it's all done in gcc/builtin-attrs.def

Patch

Index: include/linux/kernel.h
===================================================================
RCS file: /home/erik/cvsroot/elinux/include/linux/kernel.h,v
retrieving revision 1.1.1.143
diff -u -r1.1.1.143 kernel.h
--- linux/include/linux/kernel.h	2001/11/07 00:36:34	1.1.1.143
+++ linux/include/linux/kernel.h	2001/11/07 15:49:54
@@ -60,9 +60,11 @@ 
 extern long simple_strtol(const char *,char **,unsigned int);
 extern unsigned long long simple_strtoull(const char *,char **,unsigned int);
 extern long long simple_strtoll(const char *,char **,unsigned int);
-extern int sprintf(char * buf, const char * fmt, ...);
+extern int sprintf(char * buf, const char * fmt, ...)
+	__attribute__ ((format (printf, 2, 3)));
 extern int vsprintf(char *buf, const char *, va_list);
-extern int snprintf(char * buf, size_t size, const char *fmt, ...);
+extern int snprintf(char * buf, size_t size, const char * fmt, ...)
+	__attribute__ ((format (printf, 3, 4)));
 extern int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
 
 extern int sscanf(const char *, const char *, ...)