fix memory corruptions caused by outofbounds-writes in uTouch
authorsheepluva
Fri, 29 Apr 2016 23:42:37 +0200
changeset 11782 77afc967f38e
parent 11781 f2031643fe98
child 11783 d8a9be46dede
fix memory corruptions caused by outofbounds-writes in uTouch
hedgewars/uTouch.pas
--- a/hedgewars/uTouch.pas	Fri Apr 29 19:01:52 2016 +0200
+++ b/hedgewars/uTouch.pas	Fri Apr 29 23:42:37 2016 +0200
@@ -359,12 +359,12 @@
     xCursor, yCursor, index : LongInt;
 begin
     //Check array sizes
-    if length(fingers) < pointerCount then
-    begin
-        setLength(fingers, length(fingers)*2);
-        for index := length(fingers) div 2 to length(fingers) do
+    while Length(fingers) <= pointerCount do
+        begin
+        setLength(fingers, Length(fingers)*2);
+        for index := Length(fingers) div 2 to (Length(fingers)-1) do
             fingers[index].id := nilFingerId;
-    end;
+        end;
 
     xCursor := convertToCursorX(x);
     yCursor := convertToCursorY(y);
@@ -513,7 +513,7 @@
 var
     index: LongWord;
 begin
-    for index:= 0 to length(fingers) do
+    for index:= 0 to (Length(fingers)-1) do
         if fingers[index].id = id then
             begin
             findFinger:= @fingers[index];
@@ -641,7 +641,7 @@
     pointerCount:= 0;
 
     setLength(fingers, 4);
-    for index := 0 to length(fingers) do
+    for index := 0 to (Length(fingers)-1) do
         fingers[index].id := 0;
 
     rectSize:= baseRectSize;