From 9a1f14f2aacde571c62cca4043f139c284ca47d9 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Tue, 2 Oct 2018 11:34:14 +0200 Subject: [PATCH] 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 --- src/ccstruct/points.h | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/ccstruct/points.h b/src/ccstruct/points.h index a722c9dc4f..7bccbf5b1a 100644 --- a/src/ccstruct/points.h +++ b/src/ccstruct/points.h @@ -23,6 +23,7 @@ #include // for sqrt, atan2 #include #include "elst.h" +#include "errcode.h" // for ASSERT_HOST #include "platform.h" // for DLLSYM class FCOORD; @@ -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; } @@ -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; }