Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid variable length arrays #15577

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions arch/sim/src/cmake/Toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ if(NOT WIN32)
-ffunction-sections
-fdata-sections
-Wall
-Wvla
-Wshadow
-Wundef
-Wno-attributes
Expand Down
4 changes: 2 additions & 2 deletions boards/sim/sim/sim/scripts/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ ARCHCXXFLAGS += -fvisibility=hidden
ARCHCFLAGS += -ffunction-sections -fdata-sections
ARCHCXXFLAGS += -ffunction-sections -fdata-sections

ARCHCFLAGS += -Wall -Wstrict-prototypes -Wshadow -Wundef -Wno-attributes -Wno-unknown-pragmas
ARCHCXXFLAGS += -Wall -Wshadow -Wundef -Wno-attributes -Wno-unknown-pragmas
ARCHCFLAGS += -Wall -Wvla -Wstrict-prototypes -Wshadow -Wundef -Wno-attributes -Wno-unknown-pragmas
ARCHCXXFLAGS += -Wall -Wvla -Wshadow -Wundef -Wno-attributes -Wno-unknown-pragmas

ifneq ($(CONFIG_LIBCXXTOOLCHAIN),y)
ARCHCXXFLAGS += -nostdinc++
Expand Down
16 changes: 14 additions & 2 deletions net/usrsock/usrsock_sendmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <arch/irq.h>

#include <sys/socket.h>
#include <nuttx/kmalloc.h>
#include <nuttx/net/net.h>
#include <nuttx/net/usrsock.h>

Expand Down Expand Up @@ -142,9 +143,18 @@ static int do_sendto_request(FAR struct usrsock_conn_s *conn,
{
};

struct iovec bufs[2 + msg->msg_iovlen];
struct iovec *bufs;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FAR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops. thank you.

size_t iovlen;
int ret;
int i;

iovlen = 2 + msg->msg_iovlen;
bufs = kmm_malloc(sizeof(*bufs) * iovlen);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we use alloca or save the buffer to conn? it isn't good to do the allocation in the hot path.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i guess we can have a special case for small iovlen.

if (bufs == NULL)
{
return -ENOMEM;
}

if (msg->msg_namelen > UINT16_MAX)
{
msg->msg_namelen = UINT16_MAX;
Expand Down Expand Up @@ -174,7 +184,9 @@ static int do_sendto_request(FAR struct usrsock_conn_s *conn,

memcpy(&bufs[2], msg->msg_iov, sizeof(struct iovec) * msg->msg_iovlen);

return usrsock_do_request(conn, bufs, nitems(bufs));
ret = usrsock_do_request(conn, bufs, iovlen);
kmm_free(bufs);
return ret;
}

/****************************************************************************
Expand Down
Loading