Skip to content

Commit 1055024

Browse files
committed
Merge pull request #1456 from pguyot/w01/fix-esp-idf-54-warning
Fix dubious logic revealed by esp idf 5.4 warning These changes are made under both the "Apache 2.0" and the "GNU Lesser General Public License 2.1 or later" license terms (dual license). SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
2 parents 55fb870 + 46cde98 commit 1055024

File tree

1 file changed

+7
-3
lines changed
  • src/platforms/esp32/components/avm_sys

1 file changed

+7
-3
lines changed

src/platforms/esp32/components/avm_sys/sys.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -677,12 +677,12 @@ static void *select_thread_loop(void *arg)
677677
{
678678
GlobalContext *glb = arg;
679679
struct ESP32PlatformData *platform = glb->platform_data;
680-
struct pollfd *fds = malloc(0);
680+
struct pollfd *fds = NULL;
681681
while (!platform->select_thread_exit) {
682682
int select_events_poll_count = platform->select_events_poll_count;
683683
int poll_count = 1;
684684
int fd_index;
685-
if (select_events_poll_count < 0) {
685+
if (fds == NULL || select_events_poll_count < 0) {
686686
// Means it is dirty and should be rebuilt.
687687
struct ListHead *select_events = synclist_wrlock(&glb->select_events);
688688
size_t select_events_new_count;
@@ -692,7 +692,11 @@ static void *select_thread_loop(void *arg)
692692
select_events_new_count = select_events_poll_count;
693693
}
694694

695-
fds = realloc(fds, sizeof(struct pollfd) * (poll_count + select_events_new_count));
695+
if (fds) {
696+
fds = realloc(fds, sizeof(struct pollfd) * (poll_count + select_events_new_count));
697+
} else {
698+
fds = malloc(sizeof(struct pollfd) * (poll_count + select_events_new_count));
699+
}
696700

697701
fds[0].fd = platform->signal_fd;
698702
fds[0].events = POLLIN;

0 commit comments

Comments
 (0)