-
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
Conversation
use heap allocation instead. variable length array is a C99 feature, which should not be used in the common code. besides that, stack consumption with the unchecked user-given size a bad idea in general.
[Experimental Bot, please feedback here] Fill In The Commit Message: This PR contains a Commit with an Empty Commit Message. Please fill in the Commit Message with the PR Summary. SummaryThis PR lacks a summary. The author needs to provide information on the necessity of the change, the affected functional code, the mechanics of the change, and related NuttX issues/PRs. Without this, it's impossible to determine if it meets requirements. ImpactThe impact assessment is entirely missing. The author needs to address all listed impact areas (user, build, hardware, documentation, security, compatibility) with either "NO" or a "YES" followed by a description. Without this, the PR doesn't meet requirements. TestingThe testing section is incomplete. While the template is present, the author hasn't filled in any information about the build hosts, targets, or provided any testing logs before and after the change. This makes it impossible to assess if the changes work as intended and thus the PR does not meet the requirements. |
@@ -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; |
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.
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 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.
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.
i guess we can have a special case for small iovlen.
Summary
cf. #15572
Impact
Testing