From dad25049cec0e30ca9771e435064ebf853d97bba Mon Sep 17 00:00:00 2001 From: Sandrine Bailleux Date: Thu, 5 Feb 2015 15:42:31 +0000 Subject: Enable type-checking of arguments passed to printf() et al. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch modifies the declarations of the functions printf() et al. and adds the right GCC attribute to request the compiler to check the type of the arguments passed to these functions against the given format string. This will ensure that the compiler outputs warning messages like the following whenever it detects an inconsistency: file.c:42: warning: format ‘%d’ expects type ‘int’, but argument 3 has type ‘long int’ It also fixes the type mismatch inconsistencies that it revealed across the code base. NOTE: THIS PATCH MAY FORCE PLATFORM PORTS OR SP/SPDS THAT USE THE PRINTF FAMILY OF FUNCTIONS TO FIX ANY TYPE MISMATCH INCONSISTENCIES. Change-Id: If36bb54ec7d6dd2cb4791d89b02a24ac13fd2df6 --- include/stdlib/stdio.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'include/stdlib/stdio.h') diff --git a/include/stdlib/stdio.h b/include/stdlib/stdio.h index 60e081b4..57e5c7fa 100644 --- a/include/stdlib/stdio.h +++ b/include/stdlib/stdio.h @@ -58,12 +58,13 @@ typedef __ssize_t ssize_t; #define EOF (-1) -int printf(const char * __restrict, ...); +int printf(const char * __restrict, ...) __printflike(1, 2); int putchar(int); int puts(const char *); -int sprintf(char * __restrict, const char * __restrict, ...); +int sprintf(char * __restrict, const char * __restrict, ...) + __printflike(2, 3); int vsprintf(char * __restrict, const char * __restrict, - __va_list); + __va_list) __printflike(2, 0); int sscanf(const char *__restrict, char const *__restrict, ...); -- cgit