mirror of https://github.com/eclipse/paho.mqtt.c
Handle 0 length arrays properly #1356
This commit is contained in:
parent
3933f8b796
commit
fd213a8461
33
src/Socket.c
33
src/Socket.c
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009, 2022 IBM Corp., Ian Craggs and others
|
||||
* Copyright (c) 2009, 2023 IBM Corp., Ian Craggs and others
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v2.0
|
||||
|
|
@ -516,17 +516,40 @@ SOCKET Socket_getReadySocket(int more_work, int timeout, mutex_type mutex, int*
|
|||
if (mod_s.nfds != mod_s.saved.nfds)
|
||||
{
|
||||
mod_s.saved.nfds = mod_s.nfds;
|
||||
if (mod_s.saved.fds_read)
|
||||
if (mod_s.nfds == 0)
|
||||
{
|
||||
if (mod_s.saved.fds_read)
|
||||
{
|
||||
free(mod_s.saved.fds_read);
|
||||
mod_s.saved.fds_read = NULL;
|
||||
}
|
||||
}
|
||||
else if (mod_s.saved.fds_read)
|
||||
mod_s.saved.fds_read = realloc(mod_s.saved.fds_read, mod_s.nfds * sizeof(struct pollfd));
|
||||
else
|
||||
mod_s.saved.fds_read = malloc(mod_s.nfds * sizeof(struct pollfd));
|
||||
if (mod_s.saved.fds_write)
|
||||
|
||||
if (mod_s.nfds == 0)
|
||||
{
|
||||
if (mod_s.saved.fds_write)
|
||||
{
|
||||
free(mod_s.saved.fds_write);
|
||||
mod_s.saved.fds_write = NULL;
|
||||
}
|
||||
}
|
||||
else if (mod_s.saved.fds_write)
|
||||
mod_s.saved.fds_write = realloc(mod_s.saved.fds_write, mod_s.nfds * sizeof(struct pollfd));
|
||||
else
|
||||
mod_s.saved.fds_write = malloc(mod_s.nfds * sizeof(struct pollfd));
|
||||
}
|
||||
memcpy(mod_s.saved.fds_read, mod_s.fds_read, mod_s.nfds * sizeof(struct pollfd));
|
||||
memcpy(mod_s.saved.fds_write, mod_s.fds_write, mod_s.nfds * sizeof(struct pollfd));
|
||||
if (mod_s.fds_read == NULL)
|
||||
mod_s.saved.fds_read = NULL;
|
||||
else
|
||||
memcpy(mod_s.saved.fds_read, mod_s.fds_read, mod_s.nfds * sizeof(struct pollfd));
|
||||
if (mod_s.fds_write == NULL)
|
||||
mod_s.saved.fds_write = NULL;
|
||||
else
|
||||
memcpy(mod_s.saved.fds_write, mod_s.fds_write, mod_s.nfds * sizeof(struct pollfd));
|
||||
|
||||
if (mod_s.saved.nfds == 0)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue