Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit afb704ba authored by Josef Weidendorfer's avatar Josef Weidendorfer

Fix compare functions used by std::sort

In commit 3306cb3e (Nov 22, 2016), the obsolete qSort function
was replaced by std::sort.

However, there is a subtile difference: qSort was able to
cope with non-strict weak ordering given back by the compare
function, whereas std::sort is not, possibly resulting in
out-of-bound accesses and crashes.

In a previous commit 2856bba6, a compare function in treemap.cpp
was fixed, but we missed fixing a few other compare functions which
now are used by std::sort.

This fixes bug 385127.
parent c49645f4
......@@ -84,6 +84,10 @@ public:
const CanvasEdge* ce2 = ge2->canvasEdge();
// sort invisible edges (ie. without matching CanvasEdge) in front
if (!ce1 && !ce2) {
// strict ordering required for std::sort
return (ge1 < ge2);
}
if (!ce1) return true;
if (!ce2) return false;
......
......@@ -494,8 +494,11 @@ bool instrJumpLowLessThan(const TraceInstrJump* ij1,
if (addr1Low != addr2Low) return (addr1Low < addr2Low);
// jump ends come before jump starts
if (addr1Low == ij1->instrTo()->addr()) return true;
if (addr2Low == ij2->instrTo()->addr()) return false;
bool low1IsEnd = (addr1Low == ij1->instrTo()->addr());
bool low2IsEnd = (addr2Low == ij2->instrTo()->addr());
if (low1IsEnd && !low2IsEnd) return true;
if (low2IsEnd && !low1IsEnd) return false;
// both the low address of jump 1 and 2 are end or start
return (addr1High < addr2High);
}
......@@ -510,8 +513,11 @@ bool instrJumpHighLessThan(const TraceInstrJump* ij1,
if (addr1High != addr2High) return (addr1High < addr2High);
// jump ends come before jump starts
if (addr1High == ij1->instrTo()->addr()) return true;
if (addr2High == ij2->instrTo()->addr()) return false;
bool high1IsEnd = (addr1High == ij1->instrTo()->addr());
bool high2IsEnd = (addr2High == ij2->instrTo()->addr());
if (high1IsEnd && !high2IsEnd) return true;
if (high2IsEnd && !high1IsEnd) return false;
// both the high address of jump 1 and 2 are end or start
return (addr1Low < addr2Low);
}
......
......@@ -557,8 +557,11 @@ bool lineJumpLowLessThan(const TraceLineJump* jump1,
if (line1Low != line2Low) return (line1Low < line2Low);
// jump ends come before jump starts
if (line1Low == jump1->lineTo()->lineno()) return true;
if (line2Low == jump2->lineTo()->lineno()) return false;
bool low1IsEnd = (line1Low == jump1->lineTo()->lineno());
bool low2IsEnd = (line2Low == jump2->lineTo()->lineno());
if (low1IsEnd && !low2IsEnd) return true;
if (low2IsEnd && !low1IsEnd) return false;
// both the low line of jump 1 and 2 are end or start
return (line1High < line2High);
}
......@@ -573,8 +576,11 @@ bool lineJumpHighLessThan(const TraceLineJump* jump1,
if (line1High != line2High) return (line1High < line2High);
// jump ends come before jump starts
if (line1High == jump1->lineTo()->lineno()) return true;
if (line2High == jump2->lineTo()->lineno()) return false;
bool high1IsEnd = (line1High == jump1->lineTo()->lineno());
bool high2IsEnd = (line2High == jump2->lineTo()->lineno());
if (high1IsEnd && !high2IsEnd) return true;
if (high2IsEnd && !high1IsEnd) return false;
// both the high line of jump 1 and 2 are end or start
return (line1Low < line2Low);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment