[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mingw-users
Subject:    [Mingw-users] Printf fomat checking
From:       Aron Rubin <aronrubin () gmail ! com>
Date:       2009-03-19 22:28:14
Message-ID: c46d99050903191528i159f2a94w5acf86102513c97f () mail ! gmail ! com
[Download RAW message or body]

At the risk of bringing up the new non-C99 stdio functions activated
by explicitly asking for C99 compliance again... I noticed the
formatted argument check is broken. I have remedied the missing
annotations/attributes in my local copy with the attached patch. I
attempted to match the style of other attribute use there.

["format_attributes-2009041901.patch" (text/x-patch)]

--- _mingw.h	2009-03-19 17:48:02 -0400
+++ _mingw.h	2009-03-19 17:55:18 -0400
@@ -204,6 +204,20 @@
 #define __MINGW_NOTHROW
 #endif /* GNUC >= 3.3 */
 
+#if  __MINGW_GNUC_PREREQ (3, 3)
+#define __MINGW_ATTRIB_FORMAT( archetype, fmt_str_idx, first_varg_idx ) \
+  __attribute__((format( archetype, fmt_str_idx, first_varg_idx )))
+#define __MINGW_FMT_PRINTF( fmt_str_idx ) \
+  __attribute__((format( printf, fmt_str_idx, fmt_str_idx + 1 )))
+#define __MINGW_FMT_SCANF( fmt_str_idx ) \
+  __attribute__((format( scanf, fmt_str_idx, fmt_str_idx + 1 )))
+#else
+#define __MINGW_ATTRIB_FORMAT( archetype, fmt_str_idx, first_varg_idx )
+#define __MINGW_FMT_PRINTF( fmt_str_idx )
+#define __MINGW_FMT_SCANF( fmt_str_idx )
+#endif
+
+
 /* TODO: Mark (almost) all CRT functions as __MINGW_NOTHROW.  This will
 allow GCC to optimize away some EH unwind code, at least in DW2 case.  */
 
--- stdio.h	2009-03-19 18:10:19 -0400
+++ stdio.h	2009-03-19 18:12:51 -0400
@@ -201,10 +201,14 @@ _CRTIMP void __cdecl __MINGW_NOTHROW	set
 #undef  __mingw_stdio_redirect__
 #define __mingw_stdio_redirect__(F) __cdecl __MINGW_NOTHROW __mingw_##F
 
-extern int __mingw_stdio_redirect__(fprintf)(FILE*, const char*, ...);
-extern int __mingw_stdio_redirect__(printf)(const char*, ...);
-extern int __mingw_stdio_redirect__(sprintf)(char*, const char*, ...);
-extern int __mingw_stdio_redirect__(snprintf)(char*, size_t, const char*, ...);
+extern int __mingw_stdio_redirect__(fprintf)(FILE*, const char*, ...)
+  __MINGW_FMT_PRINTF( 2 );
+extern int __mingw_stdio_redirect__(printf)(const char*, ...)
+  __MINGW_FMT_PRINTF( 1 );
+extern int __mingw_stdio_redirect__(sprintf)(char*, const char*, ...)
+  __MINGW_FMT_PRINTF( 2 );
+extern int __mingw_stdio_redirect__(snprintf)(char*, size_t, const char*, ...)
+  __MINGW_FMT_PRINTF( 3 );
 extern int __mingw_stdio_redirect__(vfprintf)(FILE*, const char*, __VALIST);
 extern int __mingw_stdio_redirect__(vprintf)(const char*, __VALIST);
 extern int __mingw_stdio_redirect__(vsprintf)(char*, const char*, __VALIST);
@@ -238,7 +242,7 @@ extern int __mingw_stdio_redirect__(vsnp
 #  define __mingw_stdio_redirect__  static __cdecl __MINGW_NOTHROW
 # endif
 
-__mingw_stdio_redirect__
+__mingw_stdio_redirect__  __MINGW_FMT_PRINTF( 2 )
 int fprintf (FILE *__stream, const char *__format, ...)
 {
   register int __retval;
@@ -248,7 +252,7 @@ int fprintf (FILE *__stream, const char 
   return __retval;
 }
 
-__mingw_stdio_redirect__
+__mingw_stdio_redirect__ __MINGW_FMT_PRINTF( 1 )
 int printf (const char *__format, ...)
 {
   register int __retval;
@@ -258,7 +262,7 @@ int printf (const char *__format, ...)
   return __retval;
 }
 
-__mingw_stdio_redirect__
+__mingw_stdio_redirect__ __MINGW_FMT_PRINTF( 2 )
 int sprintf (char *__stream, const char *__format, ...)
 {
   register int __retval;
@@ -290,9 +294,12 @@ int vsprintf (char *__stream, const char
 /*
  * Default configuration: simply direct all calls to MSVCRT...
  */
-_CRTIMP int __cdecl __MINGW_NOTHROW fprintf (FILE*, const char*, ...);
-_CRTIMP int __cdecl __MINGW_NOTHROW printf (const char*, ...);
-_CRTIMP int __cdecl __MINGW_NOTHROW sprintf (char*, const char*, ...);
+_CRTIMP int __cdecl __MINGW_NOTHROW fprintf (FILE*, const char*, ...)
+  __MINGW_FMT_PRINTF( 2 );
+_CRTIMP int __cdecl __MINGW_NOTHROW printf (const char*, ...)
+  __MINGW_FMT_PRINTF( 1 );
+_CRTIMP int __cdecl __MINGW_NOTHROW sprintf (char*, const char*, ...)
+  __MINGW_FMT_PRINTF( 2 );
 _CRTIMP int __cdecl __MINGW_NOTHROW vfprintf (FILE*, const char*, __VALIST);
 _CRTIMP int __cdecl __MINGW_NOTHROW vprintf (const char*, __VALIST);
 _CRTIMP int __cdecl __MINGW_NOTHROW vsprintf (char*, const char*, __VALIST);
@@ -305,9 +312,12 @@ _CRTIMP int __cdecl __MINGW_NOTHROW vspr
 #undef  __mingw_stdio_redirect__
 #define __mingw_stdio_redirect__(F) __cdecl __MINGW_NOTHROW __msvcrt_##F
 
-_CRTIMP int __mingw_stdio_redirect__(fprintf)(FILE*, const char*, ...);
-_CRTIMP int __mingw_stdio_redirect__(printf)(const char*, ...);
-_CRTIMP int __mingw_stdio_redirect__(sprintf)(char*, const char*, ...);
+_CRTIMP int __mingw_stdio_redirect__(fprintf)(FILE*, const char*, ...)
+  __MINGW_FMT_PRINTF( 2 );
+_CRTIMP int __mingw_stdio_redirect__(printf)(const char*, ...)
+  __MINGW_FMT_PRINTF( 1 );
+_CRTIMP int __mingw_stdio_redirect__(sprintf)(char*, const char*, ...)
+  __MINGW_FMT_PRINTF( 2 );
 _CRTIMP int __mingw_stdio_redirect__(vfprintf)(FILE*, const char*, __VALIST);
 _CRTIMP int __mingw_stdio_redirect__(vprintf)(const char*, __VALIST);
 _CRTIMP int __mingw_stdio_redirect__(vsprintf)(char*, const char*, __VALIST);
@@ -316,7 +326,8 @@ _CRTIMP int __mingw_stdio_redirect__(vsp
 
 /* The following pair ALWAYS refer to the MSVCRT implementations...
  */
-_CRTIMP int __cdecl __MINGW_NOTHROW _snprintf (char*, size_t, const char*, ...);
+_CRTIMP int __cdecl __MINGW_NOTHROW _snprintf (char*, size_t, const char*, ...)
+  __MINGW_FMT_PRINTF( 3 );
 _CRTIMP int __cdecl __MINGW_NOTHROW _vsnprintf (char*, size_t, const char*, __VALIST);
 
 #ifndef __NO_ISOCEXT  /* externs in libmingwex.a */
@@ -327,7 +338,8 @@ _CRTIMP int __cdecl __MINGW_NOTHROW _vsn
  * compatible with C99, but the following are; if you want the MSVCRT
  * behaviour, you *must* use the Microsoft uglified names.
  */
-int __cdecl __MINGW_NOTHROW snprintf (char *, size_t, const char *, ...);
+int __cdecl __MINGW_NOTHROW snprintf (char *, size_t, const char *, ...)
+  __MINGW_FMT_PRINTF( 3 );
 int __cdecl __MINGW_NOTHROW vsnprintf (char *, size_t, const char *, __VALIST);
 
 int __cdecl __MINGW_NOTHROW vscanf (const char * __restrict__, __VALIST);
@@ -342,9 +354,13 @@ int __cdecl __MINGW_NOTHROW vsscanf (con
  * Formatted Input
  */
 
-_CRTIMP int __cdecl __MINGW_NOTHROW	fscanf (FILE*, const char*, ...);
-_CRTIMP int __cdecl __MINGW_NOTHROW	scanf (const char*, ...);
-_CRTIMP int __cdecl __MINGW_NOTHROW	sscanf (const char*, const char*, ...);
+_CRTIMP int __cdecl __MINGW_NOTHROW	fscanf (FILE*, const char*, ...)
+  __MINGW_FMT_SCANF( 2 );
+_CRTIMP int __cdecl __MINGW_NOTHROW	scanf (const char*, ...)
+  __MINGW_FMT_SCANF( 1 );
+_CRTIMP int __cdecl __MINGW_NOTHROW	sscanf (const char*, const char*, ...)
+  __MINGW_FMT_SCANF( 2 );
+
 /*
  * Character Input and Output Functions
  */


------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com

-- 
_______________________________________________
MinGW-users mailing list
MinGW-users@lists.sourceforge.net

This list observes the Etiquette found at 
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.

Most annoying abuses are:
1) Top posting
2) Thread hijacking
3) HTML/MIME encoded mail
4) Improper quoting
5) Improper trimming
_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic