Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix Integer Over/Underflow in DynArrayCompareInteger

If PInteger(Item1)^ = High(Integer) and PInteger(Item2)^ < 0 then
PInteger(Item1)^ - PInteger(Item2) will overflow and dependant on
{$OverFlowChecks} directive either crash or give wrong ordering. Use safe
compare function also used for other types that don't fit inside Integer
  • Loading branch information...
commit 31bce4791cd0ab94511dccb0360be6b21eb3f0eb 1 parent ad1d1c8
@rf232 rf232 authored
Showing with 7 additions and 1 deletion.
  1. +7 −1 jcl/source/common/JclSysUtils.pas
View
8 jcl/source/common/JclSysUtils.pas
@@ -1581,7 +1581,13 @@ function DynArrayCompareSmallInt(Item1, Item2: Pointer): Integer;
function DynArrayCompareInteger(Item1, Item2: Pointer): Integer;
begin
- Result := PInteger(Item1)^ - PInteger(Item2)^;
+ if PInteger(Item1)^ < PInteger(Item2)^ then
+ Result := -1
+ else
+ if PInteger(Item1)^ > PInteger(Item2)^ then
+ Result := 1
+ else
+ Result := 0;
end;
function DynArrayCompareCardinal(Item1, Item2: Pointer): Integer;
Please sign in to comment.
Something went wrong with that request. Please try again.