# HG changeset patch # User asl # Date 1111947298 0 # Node ID ae242bae5abc120b6a07579796b3ce18d56adc3a # Parent 4f6bcb240e171f4eb9125d5336b083114a995b21 * include/diag.h: Added CYGBLD_ATTRIB_PRINTF_FORMAT where appropriate to get the compiler to do more checking. * src/diag.cxx (diag_dump_buf_with_offset_16bit): Fix compiler warning caused by above change. diff --git a/packages/infra/current/ChangeLog b/packages/infra/current/ChangeLog --- a/packages/infra/current/ChangeLog +++ b/packages/infra/current/ChangeLog @@ -1,3 +1,10 @@ +2005-03-27 Andrew Lunn + + * include/diag.h: Added CYGBLD_ATTRIB_PRINTF_FORMAT where + appropriate to get the compiler to do more checking. + * src/diag.cxx (diag_dump_buf_with_offset_16bit): Fix compiler warning + caused by above change. + 2005-02-08 Andrew Lunn * tests/diag_sprintf1.c diff --git a/packages/infra/current/include/cyg_type.h b/packages/infra/current/include/cyg_type.h --- a/packages/infra/current/include/cyg_type.h +++ b/packages/infra/current/include/cyg_type.h @@ -375,6 +375,14 @@ typedef cyg_haladdrword CYG_ADDRWORD; # define CYGBLD_ATTRIB_PRINTF_FORMAT(__format__, __args__) \ __attribute__((format (printf, __format__, __args__))) +// Teach compiler how to check format of scanf-like functions +# define CYGBLD_ATTRIB_SCANF_FORMAT(__format__, __args__) \ + __attribute__((format (scanf, __format__, __args__))) + +// Teach compiler how to check format of strftime-like functions +# define CYGBLD_ATTRIB_STRFTIME_FORMAT(__format__, __args__) \ + __attribute__((format (strftime, __format__, __args__))) + #else // non-GNU # define CYGBLD_ATTRIB_CONSTRUCTOR @@ -400,6 +408,11 @@ typedef cyg_haladdrword CYG_ADDRWORD; # define CYGBLD_ATTRIB_PRINTF_FORMAT(__format__, __args__) +# define CYGBLD_ATTRIB_SCANF_FORMAT(__format__, __args__) + +# define CYGBLD_ATTRIB_STRFTIME_FORMAT(__format__, __args__) + + #endif // How to define weak aliases. Currently this is simply a mixture of the diff --git a/packages/infra/current/include/diag.h b/packages/infra/current/include/diag.h --- a/packages/infra/current/include/diag.h +++ b/packages/infra/current/include/diag.h @@ -92,13 +92,18 @@ externC void diag_dump_buf_with_offset_1 CYG_ADDRWORD s, cyg_uint16 *base); -externC int diag_printf( const char *fmt, ... ); /* Formatted print */ +/* Formatted print */ +externC int diag_printf( const char *fmt, ... ) CYGBLD_ATTRIB_PRINTF_FORMAT(1,2); externC void diag_init_putc(void (*putc)(char c, void **param)); -externC int diag_sprintf(char *buf, const char *fmt, ...); -externC int diag_snprintf(char *buf, size_t len, const char *fmt, ...); -externC int diag_vsprintf(char *buf, const char *fmt, va_list ap); -externC int diag_vprintf(const char *fmt, va_list ap); +externC int diag_sprintf(char *buf, const char *fmt, ...) + CYGBLD_ATTRIB_PRINTF_FORMAT(2,3); +externC int diag_snprintf(char *buf, size_t len, const char *fmt, ...) + CYGBLD_ATTRIB_PRINTF_FORMAT(3,4); +externC int diag_vsprintf(char *buf, const char *fmt, va_list ap) + CYGBLD_ATTRIB_PRINTF_FORMAT(2,0); +externC int diag_vprintf(const char *fmt, va_list ap) + CYGBLD_ATTRIB_PRINTF_FORMAT(1,0); /*---------------------------------------------------------------------------*/ diff --git a/packages/infra/current/src/diag.cxx b/packages/infra/current/src/diag.cxx --- a/packages/infra/current/src/diag.cxx +++ b/packages/infra/current/src/diag.cxx @@ -654,7 +654,7 @@ diag_dump_buf_with_offset_32bit(cyg_uint if (base) { diag_printf("%08X: ", (CYG_ADDRWORD)p - (CYG_ADDRWORD)base); } else { - diag_printf("%08X: ", p); + diag_printf("%08X: ", (CYG_ADDRWORD)p); } for (i = 0; i < 4; i++) { if (i < (int)s/4) { @@ -688,7 +688,7 @@ diag_dump_buf_with_offset_16bit(cyg_uint if (base) { diag_printf("%08X: ", (CYG_ADDRWORD)p - (CYG_ADDRWORD)base); } else { - diag_printf("%08X: ", p); + diag_printf("%08X: ", (CYG_ADDRWORD)p); } for (i = 0; i < 8; i++) { if (i < (int)s/2) {