3 ms·
This is cool, definitely new to me. I do wonder if this just moves the problem though. As the article explains: > One crucial requirement is that the counter m
by azeemba 2y ago
This is cool, definitely new to me. I do wonder if this just moves the problem though. As the article explains:
> One crucial requirement is that the counter must be initialized before the first reference to the flexible-array member. Another requirement is that the array must always contain at least as many elements as indicated by the counter.
This means as the array is initialized and updated, you must keep the counter updated with it. Its just as easy to screw that up than it is to screw up the general problem of accessing elements that are out-of-bounds
- db48x 2y agoIt’s just as easy to make that mistake, but at least then the compiler can issue a warning.
- akira2501 2y agoIt's better than that. If you use FORTIFY_SOURCE then you will get _runtime_ bounds checking. So, while you still have to make sure your structure is sane, now the runtime can play along too.
- db48x 2y agoTrue, but compile time warnings beat runtime checks every time. Well, as long as people turn the warnings into errors so that they cannot just be ignored.