Do not use alloca inside a loop #21
No reviewers
Labels
No milestone
No project
No assignees
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: Docs/defensive-coding-guide#21
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "alloca-loops"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The advise is good, but
alloca
memory can be deallocated on scope exit if the scope contains a VLA. I don't think compilers diagnose this properly.From the man page it says:
If it is deallocated on scope exit it goes against the description, doesn't it?
Huh, it turns out I misremembered, and according to the GCC documentation, calling
alloca
inhibits VLA deallocation, not the other way round:https://gcc.gnu.org/onlinedocs/gcc/Variable-Length.html
A short test program confirms this:
@fweimer so we are good to commit this right?
@huzaifas It's still not completely accurate.
Maybe add a sentence that discourages mixing VLAs and
alloca
in the same function?Ok I will add that!
@ret2libc ok, i will wait for the change in the patch, before i commit :)
1 new commit added
Notify about mixing VLA and alloca
@huzaifas @fweimer sentence added about mixing VLA and alloca.
rebased onto
34c100361b
Pull-Request has been merged by huzaifas