3 ms·
I am not sure restricting the type of the size parameter makes VLAs a good idea if such a constraint is necessary. It seems brittle and too subtle. Will future
by asveikau 8y ago
I am not sure restricting the type of the size parameter makes VLAs a good idea if such a constraint is necessary. It seems brittle and too subtle. Will future readers get that this is the reason for the type choice? Aren't you one refactor away from making it effectively unbounded again? (I suppose a typedef and a comment can make the choice seem more explicit.)
Of course whether any of this matters will depend on the specifics of the matter, kernel code being the most conservative by necessity.
- vlovich123 8y agoI'm not sure how a restriction would work. The kernel stack is 16kb (meaning uint16_t is already unsafe) & you don't actually know where in the stack you are when creating the VLA so even if you did restrict yourself to uint8_t that doesn't protect you in any way.
- tropo 8y agoYou're no less protected than you are when you call a function. Nothing ensures that a function can safely be called. uint8_t is effective protection, given the normal assumption of a stack with 4096 to 16384 bytes of space and a call stack that isn't insane. If you wish to make a formal proof of correctness, feel free to make worst-case assumptions.