3145- }
3146- if (!setExternalKeyPool.empty()) {
3147- nEnd = std::max(nEnd, *(setExternalKeyPool.rbegin()) + 1);
3148- }
3149+ int64_t index = ++m_max_keypool_index;
3150+ assert(index >= 0); // How in the hell did you use so many keys?
Signed overflow is undefined behaviour, so the compiler is allowed to optimize this assert out (it can assume overflow never happens).
heh, i almost commented that it would be clearer to check against max
Heh, but in practice it doesnt, plus its just an assert, so whatever :).
Code like this makes me go “wtf were the authors of this smoking”: asserts like this are usually optimized out, so the code looks like it’s saying that the author thought the signed overflow was kosher and that they thought it could happen here.
Would be better (non-UB, but also more clear to read) to check against std::numeric_limits<int64_t>::max()
before the increase.