VarMap stable_sort throws Invalid Comparator

Can thank Visual Studio 2019 debug build for finding this one.  Only debug build runtime error but this is a legitimate violation of C++ standards.

stable_sort requires a weak strict ordering yet inspection showed duplicates were ending up in the maplist.

The solution is complexity-wise not ideal.  But it certainly works to prevent this bug.
This commit is contained in:
Gregory Morse 2019-07-26 00:43:52 +02:00 committed by GitHub
parent fa20ba3762
commit b218cfab9d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -292,6 +292,16 @@ bool RangeHint::compareRanges(const RangeHint *a,const RangeHint *b)
return true; return true;
} }
bool RangeHint::rangesEqual(const RangeHint* a, const RangeHint* b)
{
if (a->sstart == b->sstart && a->size == b->size) {
type_metatype ameta = a->type->getMetatype();
type_metatype bmeta = b->type->getMetatype();
return (ameta == bmeta);
}
return false;
}
/// \param spc is the (stack) address space associated with this function's local variables /// \param spc is the (stack) address space associated with this function's local variables
/// \param fd is the function associated with these local variables /// \param fd is the function associated with these local variables
/// \param g is the Architecture /// \param g is the Architecture
@ -783,6 +793,9 @@ void MapState::addRange(uintb st,Datatype *ct,uint4 fl,RangeHint::RangeType rt,i
sign_extend(sst,spaceid->getAddrSize()*8-1); sign_extend(sst,spaceid->getAddrSize()*8-1);
sst = (intb)AddrSpace::addressToByte(sst,spaceid->getWordSize()); sst = (intb)AddrSpace::addressToByte(sst,spaceid->getWordSize());
RangeHint *range = new RangeHint(st,sz,sst,ct,fl,rt,hi); RangeHint *range = new RangeHint(st,sz,sst,ct,fl,rt,hi);
if (std::find_if(maplist.begin(), maplist.end(), [range](RangeHint* rh) {
return RangeHint::rangesEqual(rh, range);
}) == maplist.end())
maplist.push_back(range); maplist.push_back(range);
#ifdef OPACTION_DEBUG #ifdef OPACTION_DEBUG
if (debugon) { if (debugon) {