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
This commit is contained in:
DrZiplok@gmail.com 2010-11-23 09:09:52 +00:00
parent 906239160d
commit f30bf9cab7
2 changed files with 11 additions and 3 deletions

View File

@ -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

View File

@ -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;