-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
base: master
Are you sure you want to change the base?
avoid variable length arrays #15577
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -148,6 +148,7 @@ if(NOT WIN32) | |
-ffunction-sections | ||
-fdata-sections | ||
-Wall | ||
-Wvla | ||
-Wshadow | ||
-Wundef | ||
-Wno-attributes | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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> | ||
|
||
|
@@ -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; | ||
size_t iovlen; | ||
int ret; | ||
int i; | ||
|
||
iovlen = 2 + msg->msg_iovlen; | ||
bufs = kmm_malloc(sizeof(*bufs) * iovlen); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
@@ -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; | ||
} | ||
|
||
/**************************************************************************** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FAR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops. thank you.