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

Replace VLA usage with heap-allocated buffers #284

Merged
merged 2 commits into from
Nov 25, 2022
Merged

Replace VLA usage with heap-allocated buffers #284

merged 2 commits into from
Nov 25, 2022

Conversation

eigenraven
Copy link
Collaborator

@eigenraven eigenraven commented Nov 15, 2022

Variable length arrays are a compiler extension and not part of the base c++ language, they cause dynamic stack allocations which can silently overflow the stack, causing hard-to-debug errors at runtime which I have ran into a couple of times with large network messages.

The macros.h macros were only used once, so I just replaced the macro with its contents.
This has the additional benefit that SerializeToString (string is used as a bytes container in protobuf, not text) will only compute the size of the message once unlike the previous approach which computed it twice while serializing.

They cause dynamic stack allocations which can silently overflow the stack, causing hard-to-debug errors at runtime which I have ran into a couple of times with large network messages.
Copy link
Collaborator

@csegarragonz csegarragonz left a comment

Choose a reason for hiding this comment

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

LGTM. Just one question as I did not understand the PR description.

Copy link
Collaborator

@Shillaker Shillaker left a comment

Choose a reason for hiding this comment

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

Very nice 👍

@csegarragonz csegarragonz merged commit 2c976f3 into main Nov 25, 2022
@csegarragonz csegarragonz deleted the ban-vlas branch November 25, 2022 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants