From 8c049028d9d8057a390deb15852695e882996469 Mon Sep 17 00:00:00 2001 From: Jeff Johnston Date: Wed, 3 Dec 2014 20:25:09 +0000 Subject: [PATCH] 2014-12-03 Jeff Johnston * libc/include/inttypes.h: Only enable the 8-bit scanning macros if _WANT_IO_C99_FORMATS is defined by configuration. Add comment on why. --- newlib/ChangeLog | 6 ++++ newlib/libc/include/inttypes.h | 50 ++++++++++++++++++++++++++-------- 2 files changed, 45 insertions(+), 11 deletions(-) diff --git a/newlib/ChangeLog b/newlib/ChangeLog index cf69c05ad..fa98a7cdb 100644 --- a/newlib/ChangeLog +++ b/newlib/ChangeLog @@ -1,3 +1,9 @@ +2014-12-03 Jeff Johnston + + * libc/include/inttypes.h: Only enable the 8-bit scanning macros + if _WANT_IO_C99_FORMATS is defined by configuration. Add comment + on why. + 2014-11-28 Matthew Fortune * libc/include/machine/setjmp.h [__mips__]: Remove __mips_fpr == 64 diff --git a/newlib/libc/include/inttypes.h b/newlib/libc/include/inttypes.h index 5a8770bc6..39bf13511 100644 --- a/newlib/libc/include/inttypes.h +++ b/newlib/libc/include/inttypes.h @@ -13,6 +13,7 @@ #ifndef _INTTYPES_H #define _INTTYPES_H +#include #include #include #define __need_wchar_t @@ -22,7 +23,20 @@ /* 8-bit types */ #define __PRI8(x) __STRINGIFY(x) -#define __SCN8(x) __STRINGIFY(hh##x) + +/* NOTICE: scanning 8-bit types requires use of the hh specifier + * which is only supported on newlib platforms that + * are built with C99 I/O format support enabled. If the flag in + * newlib.h hasn't been set during configuration to indicate this, the 8-bit + * scanning format macros are disabled here as they result in undefined + * behaviour which can include memory overwrite. Overriding the flag after the + * library has been built is not recommended as it will expose the underlying + * undefined behaviour. + */ + +#if defined(_WANT_IO_C99_FORMATS) + #define __SCN8(x) __STRINGIFY(hh##x) +#endif /* _WANT_IO_C99_FORMATS */ #define PRId8 __PRI8(d) @@ -32,12 +46,17 @@ #define PRIx8 __PRI8(x) #define PRIX8 __PRI8(X) +/* Macros below are only enabled for a newlib built with C99 I/O format support. */ +#if defined(_WANT_IO_C99_FORMATS) + #define SCNd8 __SCN8(d) #define SCNi8 __SCN8(i) #define SCNo8 __SCN8(o) #define SCNu8 __SCN8(u) #define SCNx8 __SCN8(x) +#endif /* _WANT_IO_C99_FORMATS */ + #define PRIdLEAST8 __PRI8(d) #define PRIiLEAST8 __PRI8(i) @@ -46,12 +65,16 @@ #define PRIxLEAST8 __PRI8(x) #define PRIXLEAST8 __PRI8(X) -#define SCNdLEAST8 __SCN8(d) -#define SCNiLEAST8 __SCN8(i) -#define SCNoLEAST8 __SCN8(o) -#define SCNuLEAST8 __SCN8(u) -#define SCNxLEAST8 __SCN8(x) +/* Macros below are only enabled for a newlib built with C99 I/O format support. */ +#if defined(_WANT_IO_C99_FORMATS) + + #define SCNdLEAST8 __SCN8(d) + #define SCNiLEAST8 __SCN8(i) + #define SCNoLEAST8 __SCN8(o) + #define SCNuLEAST8 __SCN8(u) + #define SCNxLEAST8 __SCN8(x) +#endif /* _WANT_IO_C99_FORMATS */ #define PRIdFAST8 __PRI8(d) #define PRIiFAST8 __PRI8(i) @@ -60,11 +83,16 @@ #define PRIxFAST8 __PRI8(x) #define PRIXFAST8 __PRI8(X) -#define SCNdFAST8 __SCN8(d) -#define SCNiFAST8 __SCN8(i) -#define SCNoFAST8 __SCN8(o) -#define SCNuFAST8 __SCN8(u) -#define SCNxFAST8 __SCN8(x) +/* Macros below are only enabled for a newlib built with C99 I/O format support. */ +#if defined(_WANT_IO_C99_FORMATS) + + #define SCNdFAST8 __SCN8(d) + #define SCNiFAST8 __SCN8(i) + #define SCNoFAST8 __SCN8(o) + #define SCNuFAST8 __SCN8(u) + #define SCNxFAST8 __SCN8(x) + +#endif /* _WANT_IO_C99_FORMATS */ /* 16-bit types */ #define __PRI16(x) __STRINGIFY(x) -- 2.43.5