Fix some stuff from coverity
authorunc0rr
Tue, 11 Nov 2014 23:57:46 +0300 (2014-11-11)
changeset 10490 b30b8d39d662
parent 10489 bde3e43d7b27
child 10491 c92955fa8b67
Fix some stuff from coverity
hedgewars/uConsole.pas
hedgewars/uGears.pas
hedgewars/uGearsHandlersMess.pas
hedgewars/uGearsList.pas
hedgewars/uLand.pas
hedgewars/uLandGraphics.pas
hedgewars/uLandObjects.pas
hedgewars/uSound.pas
--- a/hedgewars/uConsole.pas	Tue Nov 11 21:55:38 2014 +0100
+++ b/hedgewars/uConsole.pas	Tue Nov 11 23:57:46 2014 +0300
@@ -24,7 +24,6 @@
 
 procedure WriteToConsole(s: shortstring);
 procedure WriteLnToConsole(s: shortstring);
-function  ShortStringAsPChar(s: shortstring): PChar;
 
 var lastConsoleline : shortstring;
 
@@ -55,14 +54,15 @@
 {$ENDIF}
     lastConsoleline:= s;
 end;
-
+{$IFDEF ANDROID}
 function ShortStringAsPChar(s: shortstring) : PChar;
 begin
     if Length(s) = High(s) then
         Dec(s[0]);
     s[Ord(Length(s))+1] := #0;
+    // returning pointer to stack, rly?
     ShortStringAsPChar:= @s[1];
 end;
-
+{$ENDIF}
 
 end.
--- a/hedgewars/uGears.pas	Tue Nov 11 21:55:38 2014 +0100
+++ b/hedgewars/uGears.pas	Tue Nov 11 23:57:46 2014 +0300
@@ -856,6 +856,8 @@
         t:= byte(s[2]);  // team
         if Length(s) > 2 then
             h:= byte(s[3])  // target hog
+        else
+            h:= 0
         end;
     // allow targetting a hog by specifying a number as the first portion of the text
     if (x < 4) and (h > byte('0')) and (h < byte('9')) then
--- a/hedgewars/uGearsHandlersMess.pas	Tue Nov 11 21:55:38 2014 +0100
+++ b/hedgewars/uGearsHandlersMess.pas	Tue Nov 11 23:57:46 2014 +0300
@@ -1828,7 +1828,7 @@
     particle: PVisualGear;
     dxdy: hwFloat;
 begin
-    if (Gear^.dY.QWordValue = 0) and (Gear^.dY.QWordValue = 0) and (TestCollisionYwithGear(Gear, 1) = 0) then
+    if (Gear^.dX.QWordValue = 0) and (Gear^.dY.QWordValue = 0) and (TestCollisionYwithGear(Gear, 1) = 0) then
         SetLittle(Gear^.dY);
     Gear^.State := Gear^.State or gstAnimation;
     if Gear^.Health < cBarrelHealth then Gear^.State:= Gear^.State and (not gstFrozen);
@@ -4036,7 +4036,7 @@
         or (iterator^.Y > Gear^.Y + r) then
             continue;
 
-        hasdxy := (((iterator^.dX.QWordValue <> 0) or (iterator^.dY.QWordValue <> 0)) or ((iterator^.State or gstMoving) = 0));
+        hasdxy := (((iterator^.dX.QWordValue <> 0) or (iterator^.dY.QWordValue <> 0)) or ((iterator^.State and gstMoving) = 0));
 
         // in case the object is not moving, let's asume it's falling towards the portal
         if not hasdxy then
--- a/hedgewars/uGearsList.pas	Tue Nov 11 21:55:38 2014 +0100
+++ b/hedgewars/uGearsList.pas	Tue Nov 11 23:57:46 2014 +0300
@@ -288,9 +288,9 @@
                     Health:= random(vobFrameTicks);
                     if gear^.Timer = 0 then Timer:= random(vobFramesCount);
                     Damage:= (random(2) * 2 - 1) * (vobVelocity + random(vobVelocity)) * 8;
-                    Tint:= (ExplosionBorderColor and RMask shl RShift) or
-                           (ExplosionBorderColor and GMask shl GShift) or
-                           (ExplosionBorderColor and BMask shl BShift) or $FF;
+                    Tint:= ((ExplosionBorderColor and RMask) shl RShift) or
+                           ((ExplosionBorderColor and GMask) shl GShift) or
+                           ((ExplosionBorderColor and BMask) shl BShift) or $FF;
                     end
                 end;
        gtGrave: begin
--- a/hedgewars/uLand.pas	Tue Nov 11 21:55:38 2014 +0100
+++ b/hedgewars/uLand.pas	Tue Nov 11 23:57:46 2014 +0300
@@ -659,8 +659,6 @@
                 begin
                 w:= LandPixels[y div 2,x div 2];
                 w:= ((w shr RShift and $FF) +  (w shr BShift and $FF) + (w shr GShift and $FF)) div 3;
-                if w > 255 then
-                    w:= 255;
                 w:= (w and $FF shl RShift) or (w and $FF shl BShift) or (w and $FF shl GShift) or (LandPixels[y div 2,x div 2] and AMask);
                 LandPixels[y,x]:= w or (LandPixels[y div 2, x div 2] and AMask)
                 end
--- a/hedgewars/uLandGraphics.pas	Tue Nov 11 21:55:38 2014 +0100
+++ b/hedgewars/uLandGraphics.pas	Tue Nov 11 23:57:46 2014 +0300
@@ -907,7 +907,7 @@
         else Land[y,x]:= lfBasic
         end
     end
-else if ((cReducedQuality and rqBlurryLand) = 0) and (LandPixels[Y, X] and AMask = 255)
+else if ((cReducedQuality and rqBlurryLand) = 0) and ((LandPixels[Y, X] and AMask) = AMask)
 and (Land[Y, X] and (lfDamaged or lfBasic) = lfBasic)
 and (Y > LongInt(topY) + 1) and (Y < LAND_HEIGHT-2) and (X > LongInt(leftX) + 1) and (X < LongInt(rightX) - 1) then
     begin
--- a/hedgewars/uLandObjects.pas	Tue Nov 11 21:55:38 2014 +0100
+++ b/hedgewars/uLandObjects.pas	Tue Nov 11 23:57:46 2014 +0300
@@ -372,8 +372,8 @@
                 inc(cnt);
                 if cnt > MaxPointsIndex then // buffer is full, do not check the rest land
                     begin
-                    y:= 5000;
-                    x:= 5000;
+                    y:= LAND_HEIGHT;
+                    x:= LAND_WIDTH;
                     end
                 end;
             inc(y, 3);
--- a/hedgewars/uSound.pas	Tue Nov 11 21:55:38 2014 +0100
+++ b/hedgewars/uSound.pas	Tue Nov 11 23:57:46 2014 +0300
@@ -435,14 +435,17 @@
         end;
 
     i:= 0;
-    while (i<8) and (VoiceList[i].snd <> sndNone) do
+    while (i <= High(VoiceList)) and (VoiceList[i].snd <> sndNone) do
         inc(i);
 
     // skip playing same sound for same hog twice
     if (i>0) and (VoiceList[i-1].snd = snd) and (VoiceList[i-1].voicepack = voicepack) then
         exit;
-    VoiceList[i].snd:= snd;
-    VoiceList[i].voicepack:= voicepack;
+    if(i <= High(VoiceList)) then
+        begin
+        VoiceList[i].snd:= snd;
+        VoiceList[i].voicepack:= voicepack;
+        end
 end;
 
 procedure PlayNextVoice;