Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix CID 1395882 (Uninitialized scalar variable)
The implementation for ICOORD only allows division by scale != 0.

Do the same for FCOORD by asserting that scale != 0.0f,
so undefined program behaviour will be caught.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
  • Loading branch information
stweil committed Oct 2, 2018
1 parent ce6ff20 commit 9a1f14f
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/ccstruct/points.h
Expand Up @@ -23,6 +23,7 @@
#include <cmath> // for sqrt, atan2
#include <cstdio>
#include "elst.h"
#include "errcode.h" // for ASSERT_HOST
#include "platform.h" // for DLLSYM

class FCOORD;
Expand Down Expand Up @@ -730,11 +731,9 @@ operator/ ( //scalar divide
const FCOORD & op1, //operands
float scale) {
FCOORD result; //output

if (scale != 0) {
result.xcoord = op1.xcoord / scale;
result.ycoord = op1.ycoord / scale;
}
ASSERT_HOST(scale != 0.0f);
result.xcoord = op1.xcoord / scale;
result.ycoord = op1.ycoord / scale;
return result;
}

Expand All @@ -749,10 +748,9 @@ inline FCOORD &
operator/= ( //scalar divide
FCOORD & op1, //operands
float scale) {
if (scale != 0) {
op1.xcoord /= scale;
op1.ycoord /= scale;
}
ASSERT_HOST(scale != 0.0f);
op1.xcoord /= scale;
op1.ycoord /= scale;
return op1;
}

Expand Down

0 comments on commit 9a1f14f

Please sign in to comment.