Skip to content

Commit 1616038

Browse files
committed
Added ZEND_ATTRIBUTE_FORMAT to some middind functions.
"%p" replaced by ZEND_LONG_FMT to avoid compilation warnings. Fixed most incorrect use cases of format specifiers.
1 parent 67e23f4 commit 1616038

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+261
-257
lines changed

Zend/zend.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ ZEND_TSRMLS_CACHE_EXTERN()
7171

7272
#ifdef HAVE_NORETURN
7373
# ifdef ZEND_NORETURN_ALIAS
74-
ZEND_COLD void zend_error_noreturn(int type, const char *format, ...) ZEND_NORETURN;
74+
ZEND_COLD void zend_error_noreturn(int type, const char *format, ...) ZEND_NORETURN ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);
7575
# else
76-
ZEND_API ZEND_COLD ZEND_NORETURN void zend_error_noreturn(int type, const char *format, ...);
76+
ZEND_API ZEND_COLD ZEND_NORETURN void zend_error_noreturn(int type, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);
7777
# endif
7878
#else
7979
# define zend_error_noreturn zend_error
@@ -267,9 +267,9 @@ extern ZEND_API char *(*zend_getenv)(char *name, size_t name_len);
267267
extern ZEND_API zend_string *(*zend_resolve_path)(const char *filename, int filename_len);
268268

269269
ZEND_API ZEND_COLD void zend_error(int type, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);
270-
ZEND_API ZEND_COLD void zend_throw_error(zend_class_entry *exception_ce, const char *format, ...);
271-
ZEND_API ZEND_COLD void zend_type_error(const char *format, ...);
272-
ZEND_API ZEND_COLD void zend_internal_type_error(zend_bool throw_exception, const char *format, ...);
270+
ZEND_API ZEND_COLD void zend_throw_error(zend_class_entry *exception_ce, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);
271+
ZEND_API ZEND_COLD void zend_type_error(const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 1, 2);
272+
ZEND_API ZEND_COLD void zend_internal_type_error(zend_bool throw_exception, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);
273273

274274
ZEND_COLD void zenderror(const char *error);
275275

Zend/zend_API.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3846,7 +3846,7 @@ ZEND_API void zend_update_property_ex(zend_class_entry *scope, zval *object, zen
38463846
EG(fake_scope) = scope;
38473847

38483848
if (!Z_OBJ_HT_P(object)->write_property) {
3849-
zend_error_noreturn(E_CORE_ERROR, "Property %s of class %s cannot be updated", name, ZSTR_VAL(Z_OBJCE_P(object)->name));
3849+
zend_error_noreturn(E_CORE_ERROR, "Property %s of class %s cannot be updated", ZSTR_VAL(name), ZSTR_VAL(Z_OBJCE_P(object)->name));
38503850
}
38513851
ZVAL_STR(&property, name);
38523852
Z_OBJ_HT_P(object)->write_property(object, &property, value, NULL);
@@ -4041,7 +4041,7 @@ ZEND_API zval *zend_read_property_ex(zend_class_entry *scope, zval *object, zend
40414041
EG(fake_scope) = scope;
40424042

40434043
if (!Z_OBJ_HT_P(object)->read_property) {
4044-
zend_error_noreturn(E_CORE_ERROR, "Property %s of class %s cannot be read", name, ZSTR_VAL(Z_OBJCE_P(object)->name));
4044+
zend_error_noreturn(E_CORE_ERROR, "Property %s of class %s cannot be read", ZSTR_VAL(name), ZSTR_VAL(Z_OBJCE_P(object)->name));
40454045
}
40464046

40474047
ZVAL_STR(&property, name);

Zend/zend_alloc.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,6 @@ typedef struct _zend_mm_free_slot zend_mm_free_slot;
193193
typedef struct _zend_mm_chunk zend_mm_chunk;
194194
typedef struct _zend_mm_huge_list zend_mm_huge_list;
195195

196-
#ifdef _WIN64
197-
# define PTR_FMT "0x%0.16I64x"
198-
#elif SIZEOF_LONG == 8
199-
# define PTR_FMT "0x%0.16lx"
200-
#else
201-
# define PTR_FMT "0x%0.8lx"
202-
#endif
203-
204196
#ifdef MAP_HUGETLB
205197
int zend_mm_use_huge_pages = 0;
206198
#endif
@@ -2515,7 +2507,7 @@ ZEND_API char* ZEND_FASTCALL _estrdup(const char *s ZEND_FILE_LINE_DC ZEND_FILE_
25152507

25162508
length = strlen(s);
25172509
if (UNEXPECTED(length + 1 == 0)) {
2518-
zend_error_noreturn(E_ERROR, "Possible integer overflow in memory allocation (%zu * %zu + %zu)", 1, length, 1);
2510+
zend_error_noreturn(E_ERROR, "Possible integer overflow in memory allocation (1 * %zu + 1)", length);
25192511
}
25202512
p = (char *) _emalloc(length + 1 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
25212513
if (UNEXPECTED(p == NULL)) {
@@ -2530,7 +2522,7 @@ ZEND_API char* ZEND_FASTCALL _estrndup(const char *s, size_t length ZEND_FILE_LI
25302522
char *p;
25312523

25322524
if (UNEXPECTED(length + 1 == 0)) {
2533-
zend_error_noreturn(E_ERROR, "Possible integer overflow in memory allocation (%zu * %zu + %zu)", 1, length, 1);
2525+
zend_error_noreturn(E_ERROR, "Possible integer overflow in memory allocation (1 * %zu + 1)", length);
25342526
}
25352527
p = (char *) _emalloc(length + 1 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
25362528
if (UNEXPECTED(p == NULL)) {
@@ -2547,7 +2539,7 @@ ZEND_API char* ZEND_FASTCALL zend_strndup(const char *s, size_t length)
25472539
char *p;
25482540

25492541
if (UNEXPECTED(length + 1 == 0)) {
2550-
zend_error_noreturn(E_ERROR, "Possible integer overflow in memory allocation (%zu * %zu + %zu)", 1, length, 1);
2542+
zend_error_noreturn(E_ERROR, "Possible integer overflow in memory allocation (1 * %zu + 1)", length);
25512543
}
25522544
p = (char *) malloc(length + 1);
25532545
if (UNEXPECTED(p == NULL)) {

Zend/zend_compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1151,7 +1151,7 @@ ZEND_API zend_class_entry *do_bind_inherited_class(const zend_op_array *op_array
11511151
* so we shut up about it. This allows the if (!defined('FOO')) { return; }
11521152
* approach to work.
11531153
*/
1154-
zend_error_noreturn(E_COMPILE_ERROR, "Cannot declare %s, because the name is already in use", zend_get_object_type(Z_OBJCE_P(lcname)), Z_STRVAL_P(lcname));
1154+
zend_error_noreturn(E_COMPILE_ERROR, "Cannot declare %s, because the name is already in use", zend_get_object_type(Z_OBJCE_P(lcname)));
11551155
}
11561156
return NULL;
11571157
}

Zend/zend_exceptions.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ ZEND_METHOD(exception, getTraceAsString)
617617
}
618618
ZEND_HASH_FOREACH_NUM_KEY_VAL(Z_ARRVAL_P(trace), index, frame) {
619619
if (Z_TYPE_P(frame) != IS_ARRAY) {
620-
zend_error(E_WARNING, "Expected array for frame %pu", index);
620+
zend_error(E_WARNING, "Expected array for frame " ZEND_ULONG_FMT, index);
621621
continue;
622622
}
623623

Zend/zend_exceptions.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ ZEND_API void zend_register_default_classes(void);
5656
/* exception_ce NULL, zend_ce_exception, zend_ce_error, or a derived class
5757
* message NULL or the message of the exception */
5858
ZEND_API ZEND_COLD zend_object *zend_throw_exception(zend_class_entry *exception_ce, const char *message, zend_long code);
59-
ZEND_API ZEND_COLD zend_object *zend_throw_exception_ex(zend_class_entry *exception_ce, zend_long code, const char *format, ...);
59+
ZEND_API ZEND_COLD zend_object *zend_throw_exception_ex(zend_class_entry *exception_ce, zend_long code, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 3, 4);
6060
ZEND_API ZEND_COLD void zend_throw_exception_object(zval *exception);
6161
ZEND_API void zend_clear_exception(void);
6262

@@ -68,8 +68,8 @@ extern ZEND_API void (*zend_throw_exception_hook)(zval *ex);
6868
ZEND_API ZEND_COLD void zend_exception_error(zend_object *exception, int severity);
6969

7070
/* do not export, in php it's available thru spprintf directly */
71-
size_t zend_spprintf(char **message, size_t max_len, const char *format, ...);
72-
zend_string *zend_strpprintf(size_t max_len, const char *format, ...);
71+
size_t zend_spprintf(char **message, size_t max_len, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 3, 4);
72+
zend_string *zend_strpprintf(size_t max_len, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);
7373

7474
END_EXTERN_C()
7575

Zend/zend_execute.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1607,7 +1607,7 @@ static zend_always_inline zval *zend_fetch_dimension_address_inner(HashTable *ht
16071607
hval = zend_dval_to_lval(Z_DVAL_P(dim));
16081608
goto num_index;
16091609
case IS_RESOURCE:
1610-
zend_error(E_NOTICE, "Resource ID#%pd used as offset, casting to integer (%pd)", Z_RES_HANDLE_P(dim), Z_RES_HANDLE_P(dim));
1610+
zend_error(E_NOTICE, "Resource ID#%d used as offset, casting to integer (%d)", Z_RES_HANDLE_P(dim), Z_RES_HANDLE_P(dim));
16111611
hval = Z_RES_HANDLE_P(dim);
16121612
goto num_index;
16131613
case IS_FALSE:
@@ -1833,7 +1833,7 @@ static zend_always_inline void zend_fetch_dimension_address_read(zval *result, z
18331833

18341834
if (UNEXPECTED(Z_STRLEN_P(container) < (size_t)((offset < 0) ? -offset : (offset + 1)))) {
18351835
if (type != BP_VAR_IS) {
1836-
zend_error(E_NOTICE, "Uninitialized string offset: %pd", offset);
1836+
zend_error(E_NOTICE, "Uninitialized string offset: " ZEND_LONG_FMT, offset);
18371837
ZVAL_EMPTY_STRING(result);
18381838
} else {
18391839
ZVAL_NULL(result);

Zend/zend_execute_API.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,7 @@ ZEND_API ZEND_NORETURN void zend_timeout(int dummy) /* {{{ */
11751175
zend_set_timeout_ex(0, 1);
11761176
#endif
11771177

1178-
zend_error_noreturn(E_ERROR, "Maximum execution time of %pd second%s exceeded", EG(timeout_seconds), EG(timeout_seconds) == 1 ? "" : "s");
1178+
zend_error_noreturn(E_ERROR, "Maximum execution time of " ZEND_LONG_FMT " second%s exceeded", EG(timeout_seconds), EG(timeout_seconds) == 1 ? "" : "s");
11791179
}
11801180
/* }}} */
11811181

@@ -1205,7 +1205,7 @@ static void zend_timeout_handler(int dummy) /* {{{ */
12051205
error_filename = "Unknown";
12061206
}
12071207

1208-
zend_spprintf(&log_buffer, 0, "\nFatal error: Maximum execution time of %pd+%pd seconds exceeded (terminated) in %s on line %d\n", EG(timeout_seconds), EG(hard_timeout), error_filename, error_lineno);
1208+
zend_spprintf(&log_buffer, 0, "\nFatal error: Maximum execution time of " ZEND_LONG_FMT "+" ZEND_LONG_FMT " seconds exceeded (terminated) in %s on line %d\n", EG(timeout_seconds), EG(hard_timeout), error_filename, error_lineno);
12091209
write(2, log_buffer, strlen(log_buffer));
12101210
_exit(1);
12111211
}

Zend/zend_hash.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ static zend_always_inline uint32_t zend_hash_check_size(uint32_t nSize)
103103
if (nSize < HT_MIN_SIZE) {
104104
nSize = HT_MIN_SIZE;
105105
} else if (UNEXPECTED(nSize >= HT_MAX_SIZE)) {
106-
zend_error_noreturn(E_ERROR, "Possible integer overflow in memory allocation (%zu * %zu + %zu)", nSize, sizeof(Bucket), sizeof(Bucket));
106+
zend_error_noreturn(E_ERROR, "Possible integer overflow in memory allocation (%u * %zu + %zu)", nSize, sizeof(Bucket), sizeof(Bucket));
107107
}
108108

109109
#if defined(ZEND_WIN32)
@@ -189,7 +189,7 @@ static void ZEND_FASTCALL zend_hash_packed_grow(HashTable *ht)
189189
{
190190
HT_ASSERT(GC_REFCOUNT(ht) == 1);
191191
if (ht->nTableSize >= HT_MAX_SIZE) {
192-
zend_error_noreturn(E_ERROR, "Possible integer overflow in memory allocation (%zu * %zu + %zu)", ht->nTableSize * 2, sizeof(Bucket), sizeof(Bucket));
192+
zend_error_noreturn(E_ERROR, "Possible integer overflow in memory allocation (%u * %zu + %zu)", ht->nTableSize * 2, sizeof(Bucket), sizeof(Bucket));
193193
}
194194
ht->nTableSize += ht->nTableSize;
195195
HT_SET_DATA_ADDR(ht, perealloc2(HT_GET_DATA_ADDR(ht), HT_SIZE(ht), HT_USED_SIZE(ht), ht->u.flags & HASH_FLAG_PERSISTENT));
@@ -869,7 +869,7 @@ static void ZEND_FASTCALL zend_hash_do_resize(HashTable *ht)
869869
pefree(old_data, ht->u.flags & HASH_FLAG_PERSISTENT);
870870
zend_hash_rehash(ht);
871871
} else {
872-
zend_error_noreturn(E_ERROR, "Possible integer overflow in memory allocation (%zu * %zu + %zu)", ht->nTableSize * 2, sizeof(Bucket) + sizeof(uint32_t), sizeof(Bucket));
872+
zend_error_noreturn(E_ERROR, "Possible integer overflow in memory allocation (%u * %zu + %zu)", ht->nTableSize * 2, sizeof(Bucket) + sizeof(uint32_t), sizeof(Bucket));
873873
}
874874
}
875875

Zend/zend_long.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ typedef int32_t zend_off_t;
5959
#ifdef ZEND_ENABLE_ZVAL_LONG64
6060
# define ZEND_LONG_FMT "%" PRId64
6161
# define ZEND_ULONG_FMT "%" PRIu64
62+
# define ZEND_XLONG_FMT "%" PRIx64
6263
# define ZEND_LONG_FMT_SPEC PRId64
6364
# define ZEND_ULONG_FMT_SPEC PRIu64
6465
# ifdef ZEND_WIN32
@@ -87,6 +88,7 @@ typedef int32_t zend_off_t;
8788
# define ZEND_STRTOUL(s0, s1, base) strtoul((s0), (s1), (base))
8889
# define ZEND_LONG_FMT "%" PRId32
8990
# define ZEND_ULONG_FMT "%" PRIu32
91+
# define ZEND_XLONG_FMT "%" PRIx32
9092
# define ZEND_LONG_FMT_SPEC PRId32
9193
# define ZEND_ULONG_FMT_SPEC PRIu32
9294
# ifdef ZEND_WIN32
@@ -117,6 +119,16 @@ typedef int32_t zend_off_t;
117119

118120
static const char long_min_digits[] = LONG_MIN_DIGITS;
119121

122+
#ifdef _WIN64
123+
# define ZEND_ADDR_FMT "0x%016I64x"
124+
#elif SIZEOF_SIZE_T == 4
125+
# define ZEND_ADDR_FMT "0x%08zx"
126+
#elif SIZEOF_SIZE_T == 8
127+
# define ZEND_ADDR_FMT "0x%016zx"
128+
#else
129+
# error "Unknown SIZEOF_SIZE_T"
130+
#endif
131+
120132
#endif /* ZEND_LONG_H */
121133

122134
/*

0 commit comments

Comments
 (0)