Skip to content

Commit 9779f45

Browse files
committed
#31: + Fix MSVC C4200 warning: replace flexible array with MSVC-compatible syntax
- Change `data[]` to `data[1]` in zend_async_waker_trigger_s structure - Adjust memory allocation calculations to account for included array element - Ensures compatibility with MSVC compiler while maintaining functionality
1 parent e5e9b2a commit 9779f45

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

Zend/zend_async_API.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ ZEND_API zend_coroutine_event_callback_t * zend_async_coroutine_callback_new(
444444

445445
static zend_always_inline zend_async_waker_trigger_t *waker_trigger_create(zend_async_event_t *event, uint32_t initial_capacity)
446446
{
447-
size_t total_size = sizeof(zend_async_waker_trigger_t) + initial_capacity * sizeof(zend_async_event_callback_t *);
447+
size_t total_size = sizeof(zend_async_waker_trigger_t) + (initial_capacity - 1) * sizeof(zend_async_event_callback_t *);
448448
zend_async_waker_trigger_t *trigger = (zend_async_waker_trigger_t *)emalloc(total_size);
449449

450450
trigger->length = 0;
@@ -458,7 +458,7 @@ static zend_always_inline zend_async_waker_trigger_t *waker_trigger_add_callback
458458
{
459459
if (trigger->length >= trigger->capacity) {
460460
uint32_t new_capacity = trigger->capacity * 2;
461-
size_t total_size = sizeof(zend_async_waker_trigger_t) + new_capacity * sizeof(zend_async_event_callback_t *);
461+
size_t total_size = sizeof(zend_async_waker_trigger_t) + (new_capacity - 1) * sizeof(zend_async_event_callback_t *);
462462

463463
zend_async_waker_trigger_t *new_trigger = (zend_async_waker_trigger_t *)erealloc(trigger, total_size);
464464
new_trigger->capacity = new_capacity;

Zend/zend_async_API.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ struct _zend_async_waker_trigger_s {
421421
uint32_t length; /* current number of callbacks */
422422
uint32_t capacity; /* allocated slots in the array */
423423
zend_async_event_t *event;
424-
zend_async_event_callback_t *data[]; /* flexible array member */
424+
zend_async_event_callback_t *data[1]; /* flexible array member */
425425
};
426426

427427
/* Dynamic array of async event callbacks with single iterator protection */

0 commit comments

Comments
 (0)