Conversation

Any C++ experts in my timeline? Here's a problem: I have some code that uses a vector and references the start of the buffer with &v[0]. Seems to be common practice. However in some situations the vector is of size zero.
1
1
So we end up having calls to functions that will reference the vector buffer as a target with an expected output size of zero. But UBSAN will throw warnings, which kinda makes sense: there is no v[0] in a vector of size zero.
3
Replying to
Using an iterator and comparing with end before using it. Using vec.begin() with a zero size array is fine though, just not dereferencing it since it already equals vec.end(). Maybe those functions should be getting passed a pair of iterators or a range, not a pointer and a size.
1
1