Skip to content

Commit 5ef7cc4

Browse files
author
Sascha Schumann
committed
Let GCC check format arguments
1 parent 095efa0 commit 5ef7cc4

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

main/php.h

+6
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,12 @@ char *strerror(int);
226226
#define LONG_MIN (- LONG_MAX - 1)
227227
#endif
228228

229+
#ifdef __GNUC__
230+
# define PHP_ATTRIBUTE_FORMAT(type, idx, first) __attribute__ ((format(type, idx, first)))
231+
#else
232+
# define PHP_ATTRIBUTE_FORMAT(type, idx, first)
233+
#endif
234+
229235
#if !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF) || PHP_BROKEN_SPRINTF || PHP_BROKEN_SNPRINTF || PHP_BROKEN_VSNPRINTF
230236
#include "snprintf.h"
231237
#endif

main/snprintf.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,17 @@ spprintf is the dynamical version of snprintf. It allocates the buffer in size
6565
#define SNPRINTF_H
6666

6767
#if !defined(HAVE_SNPRINTF) || PHP_BROKEN_SNPRINTF
68-
extern int ap_php_snprintf(char *, size_t, const char *, ...);
68+
int ap_php_snprintf(char *, size_t, const char *, ...) PHP_ATTRIBUTE_FORMAT(printf, 3, 4);
6969
#define snprintf ap_php_snprintf
7070
#endif
7171

7272
#if !defined(HAVE_VSNPRINTF) || PHP_BROKEN_VSNPRINTF
73-
extern int ap_php_vsnprintf(char *, size_t, const char *, va_list ap);
73+
int ap_php_vsnprintf(char *, size_t, const char *, va_list ap) PHP_ATTRIBUTE_FORMAT(printf, 3, 0);
7474
#define vsnprintf ap_php_vsnprintf
7575
#endif
7676

7777
#if PHP_BROKEN_SPRINTF
78-
int php_sprintf (char* s, const char* format, ...);
78+
int php_sprintf (char* s, const char* format, ...) PHP_ATTRIBUTE_FORMAT(printf, 2, 3);
7979
#define sprintf php_sprintf
8080
#endif
8181

main/spprintf.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ There is also snprintf: See difference explained in snprintf.h
3737
#include "snprintf.h"
3838

3939
BEGIN_EXTERN_C()
40-
PHPAPI extern int spprintf( char **pbuf, size_t max_len, const char *format, ...);
40+
PHPAPI int spprintf( char **pbuf, size_t max_len, const char *format, ...) PHP_ATTRIBUTE_FORMAT(printf, 3, 4);
4141

42-
PHPAPI extern int vspprintf(char **pbuf, size_t max_len, const char *format, va_list ap);
42+
PHPAPI int vspprintf(char **pbuf, size_t max_len, const char *format, va_list ap) PHP_ATTRIBUTE_FORMAT(printf, 3, 0);
4343
END_EXTERN_C()
4444

4545
#endif /* SNPRINTF_H */

0 commit comments

Comments
 (0)