<p></p>
<p><a class="user-mention" data-hovercard-type="user" data-hovercard-url="/users/b4n/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/b4n">@b4n</a>, 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[] <code>Accessing a nonexistent element through this operator is undefined behavior.</code>.</p>
<p>The assertions flag makes it checked, as the message you posted above says <code>Assertion '__builtin_expect(__n < this->size(), true)' failed</code>, and if size() is 0 its impossible for __n to be < 0.</p>
<p>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.</p>
<p>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 <code>nullptr</code>.</p>
<p><a class="user-mention" data-hovercard-type="user" data-hovercard-url="/users/hroncok/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/hroncok">@hroncok</a> yeah, I'm sure lots of other programs have bugs found when the flag makes vector indexing checked <g-emoji class="g-emoji" alias="grin" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f601.png">😁</g-emoji></p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/geany/geany-plugins/issues/1041#issuecomment-739888025">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AAIOWJ6JAYZZLC6FGUTZM2TSTTC7FANCNFSM4UHMIKQQ">unsubscribe</a>.<img src="https://github.com/notifications/beacon/AAIOWJ2PBFTKSZBXW2NKQ63STTC7FA5CNFSM4UHMIKQ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOFQM4XGI.gif" height="1" width="1" alt="" /></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/geany/geany-plugins/issues/1041#issuecomment-739888025",
"url": "https://github.com/geany/geany-plugins/issues/1041#issuecomment-739888025",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>