Skip to content

Commit

Permalink
osdetect: Fix CID 1164539 (Division or modulo by float zero)
Browse files Browse the repository at this point in the history
Avoid also a conversion from int16_t to double to float.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
  • Loading branch information
stweil committed Oct 22, 2018
1 parent 69a2e94 commit 8f615d4
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/ccmain/osdetect.cpp
Expand Up @@ -17,6 +17,10 @@
//
///////////////////////////////////////////////////////////////////////

#include <algorithm>
#include <cmath> // for std::fabs
#include <memory>

#include "osdetect.h"

#include "blobbox.h"
Expand All @@ -33,9 +37,6 @@
#include "tesseractclass.h"
#include "textord.h"

#include <algorithm>
#include <memory>

const float kSizeRatioToReject = 2.0;
const int kMinAcceptableBlobHeight = 10;

Expand Down Expand Up @@ -252,7 +253,10 @@ int os_detect(TO_BLOCK_LIST* port_blocks, OSResults* osr,
TBOX box = blob->bounding_box();
++blobs_total;

float y_x = fabs((box.height() * 1.0) / box.width());
// Catch illegal value of box width and avoid division by zero.
if (box.width() == 0) continue;
// TODO: Can height and width be negative? If not, remove fabs.
float y_x = std::fabs((box.height() * 1.0f) / box.width());
float x_y = 1.0f / y_x;
// Select a >= 1.0 ratio
float ratio = x_y > y_x ? x_y : y_x;
Expand Down

0 comments on commit 8f615d4

Please sign in to comment.