Skip to content

Commit 18d70db

Browse files
crrodrigueznielsdos
authored andcommitted
Fix gcc-14 Wcalloc-transposed-args warnings
gcc-14 and later warns of inverted arguments in calloc or calloc-like __alloc_size__ annotated functions. Closes GH-13818.
1 parent 46f45a5 commit 18d70db

File tree

5 files changed

+8
-5
lines changed

5 files changed

+8
-5
lines changed

NEWS

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ PHP NEWS
2828
. Fixed bug GH-13264 (Part 1 - Memory leak on stream filter failure).
2929
(Jakub Zelenka)
3030

31+
- Treewide:
32+
. Fix gcc-14 Wcalloc-transposed-args warnings. (Cristian Rodríguez)
33+
3134
11 Apr 2024, PHP 8.2.18
3235

3336
- Core:

ext/ffi/ffi.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -2147,7 +2147,7 @@ static zend_result zend_ffi_cdata_get_closure(zend_object *obj, zend_class_entry
21472147
if (EXPECTED(EG(trampoline).common.function_name == NULL)) {
21482148
func = &EG(trampoline);
21492149
} else {
2150-
func = ecalloc(sizeof(zend_internal_function), 1);
2150+
func = ecalloc(1, sizeof(zend_internal_function));
21512151
}
21522152
func->type = ZEND_INTERNAL_FUNCTION;
21532153
func->common.arg_flags[0] = 0;
@@ -2898,7 +2898,7 @@ static zend_function *zend_ffi_get_func(zend_object **obj, zend_string *name, co
28982898
if (EXPECTED(EG(trampoline).common.function_name == NULL)) {
28992899
func = &EG(trampoline);
29002900
} else {
2901-
func = ecalloc(sizeof(zend_internal_function), 1);
2901+
func = ecalloc(1, sizeof(zend_internal_function));
29022902
}
29032903
func->common.type = ZEND_INTERNAL_FUNCTION;
29042904
func->common.arg_flags[0] = 0;

ext/opcache/zend_accelerator_blacklist.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void zend_accel_blacklist_init(zend_blacklist *blacklist)
5858
zend_accel_blacklist_shutdown(blacklist);
5959
}
6060

61-
blacklist->entries = (zend_blacklist_entry *) calloc(sizeof(zend_blacklist_entry), blacklist->size);
61+
blacklist->entries = (zend_blacklist_entry *) calloc(blacklist->size, sizeof(zend_blacklist_entry));
6262
if (!blacklist->entries) {
6363
zend_accel_error_noreturn(ACCEL_LOG_FATAL, "Blacklist initialization: no memory\n");
6464
return;

ext/standard/proc_open.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ static zend_string* get_command_from_array(HashTable *array, char ***argv, int n
646646
static descriptorspec_item* alloc_descriptor_array(HashTable *descriptorspec)
647647
{
648648
uint32_t ndescriptors = zend_hash_num_elements(descriptorspec);
649-
return ecalloc(sizeof(descriptorspec_item), ndescriptors);
649+
return ecalloc(ndescriptors, sizeof(descriptorspec_item));
650650
}
651651

652652
static zend_string* get_string_parameter(zval *array, int index, char *param_name)

main/streams/glob_wrapper.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ static php_stream *php_glob_stream_opener(php_stream_wrapper *wrapper, const cha
225225
}
226226
}
227227

228-
pglob = ecalloc(sizeof(*pglob), 1);
228+
pglob = ecalloc(1, sizeof(*pglob));
229229

230230
if (0 != (ret = glob(path, pglob->flags & GLOB_FLAGMASK, NULL, &pglob->glob))) {
231231
#ifdef GLOB_NOMATCH

0 commit comments

Comments
 (0)