From f30bf9cab737ab34e97f7ee2734f9e0a50fbfd47 Mon Sep 17 00:00:00 2001 From: "DrZiplok@gmail.com" Date: Tue, 23 Nov 2010 09:09:52 +0000 Subject: [PATCH] Add format attributes to printf and printf_P. The latter is a bit wishful as gcc isn't smart enough to deal with what PSTR does, but with some other hackery this can be used to generate useful warnings. Add a workaround for a GCC bug that generates spurious warnings when PSTR() is used. git-svn-id: https://arducopter.googlecode.com/svn/trunk@901 f9c3cf11-9bcb-44bc-f272-b75c42450872 --- libraries/FastSerial/BetterStream.h | 9 ++++++--- libraries/FastSerial/vprintf.cpp | 5 +++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/libraries/FastSerial/BetterStream.h b/libraries/FastSerial/BetterStream.h index 9aa0011cdc..275424578c 100644 --- a/libraries/FastSerial/BetterStream.h +++ b/libraries/FastSerial/BetterStream.h @@ -22,11 +22,14 @@ public: // Stream extensions void print_P(const char *); void println_P(const char *); - void printf(const char *, ...); - void printf_P(const char *, ...); + void printf(const char *, ...) + __attribute__ ((format(__printf__, 2, 3))); + void printf_P(const char *, ...) + __attribute__ ((format(__printf__, 2, 3))); private: - void _vprintf(unsigned char, const char *, va_list); + void _vprintf(unsigned char, const char *, va_list) + __attribute__ ((format(__printf__, 3, 0))); }; #endif // __BETTERSTREAM_H diff --git a/libraries/FastSerial/vprintf.cpp b/libraries/FastSerial/vprintf.cpp index 677c0e3271..ae6f783960 100644 --- a/libraries/FastSerial/vprintf.cpp +++ b/libraries/FastSerial/vprintf.cpp @@ -72,6 +72,10 @@ extern "C" { }) */ +// Workaround for http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34734 +#undef PSTR +#define PSTR(s) (__extension__({static prog_char __c[] = (s); &__c[0];})) + #define FL_ZFILL 0x01 #define FL_PLUS 0x02 #define FL_SPACE 0x04 @@ -365,6 +369,7 @@ BetterStream::_vprintf (unsigned char in_progmem, const char *fmt, va_list ap) goto str_lpad; case 'S': + pgmstring: pnt = va_arg (ap, char *); size = strnlen_P (pnt, (flags & FL_PREC) ? prec : ~0); flags |= FL_PGMSTRING;