@b4n, by default the C++ vector index is unchecked, but no index is legal on a 
zero length vector, its UB, as the spec says about operator[] `Accessing a 
nonexistent element through this operator is undefined behavior.`.

The assertions flag makes it checked, as the message you posted above says 
`Assertion '__builtin_expect(__n < this->size(), true)' failed`, and if size() 
is 0 its impossible for __n to be < 0.

The reason its UB is that the vector would have to have at least one member to 
have memory allocated be able to access vector[0], but if size() is zero it 
need not have any memory allocated, remember std::vector is dynamic.

The reason nothing fails without the assertion is that Scintilla uses resize() 
as one of my links above points out, which does not de-allocate the vector 
memory, and its extremely likely that the vector has some memory left from 
previous operations, so its internal pointer is not `nullptr`.

@hroncok yeah, I'm sure lots of other programs have bugs found when the flag 
makes vector indexing checked :grin:

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/geany/geany-plugins/issues/1041#issuecomment-739888025

Reply via email to