4 ms·
vector::operator[] does not check bounds, neither do some libraries that I have to use, notably Google Protocol Buffers can turn a logic bug (bad index to repea
by praptak 7y ago
vector::operator[] does not check bounds, neither do some libraries that I have to use, notably Google Protocol Buffers can turn a logic bug (bad index to repeated field) into an access to unallocated memory.
Best practices do not fully eliminate segfaults. This is a practical observation.
- AlexeyBrin 7y ago> vector::operator[] does not check bounds True, but modern C++ encourages the use of range based for loops and std::algorithm functions which are safer to use. Also, if you want to check for bounds use std::vector::at which checks for bounds at runtime.
- cameldrv 7y agoIt's truly insane that after all of the water under the bridge in the past twenty years with buffer overflows that the default way to access an array in C++ is not bounds-checked. If there is a performance critical loop and you need to avoid the check, there should be a way to do it but for gods sake don't make that the default.
- deleted 7y ago[deleted]
- praptak 7y agoWouldn't that be against C++ philosophy? I mean fast by default, you need to explicitly enable anything that costs cycles.
- jupp0r 7y ago> vector::operator[] does not check bounds vector::at does check bounds, is your argument that programmers shouldn't have a choice there or do you just not know the standard library that well?