Skip to content

Commit c273f85

Browse files
committed
Improve index range check
A wrong array index must raise an assertion instead of printing an error message and continuing program execution. Remove also some float operations which are not needed because the blob_box coordinates are of type int16_t. Signed-off-by: Stefan Weil <[email protected]>
1 parent 7a99a41 commit c273f85

File tree

1 file changed

+5
-18
lines changed

1 file changed

+5
-18
lines changed

textord/makerow.cpp

+5-18
Original file line numberDiff line numberDiff line change
@@ -789,8 +789,6 @@ void compute_line_occupation( //project blobs
789789
inT32 line_count; //maxy-miny+1
790790
inT32 line_index; //of scan line
791791
int index; //array index for daft compilers
792-
float top, bottom; //coords of blob
793-
inT32 width; //of blob
794792
TO_ROW *row; //current row
795793
TO_ROW_IT row_it = block->get_rows ();
796794
BLOBNBOX *blob; //current blob
@@ -812,24 +810,13 @@ void compute_line_occupation( //project blobs
812810
blob = blob_it.data ();
813811
blob_box = blob->bounding_box ();
814812
blob_box.rotate (rotation);//de-skew it
815-
top = blob_box.top ();
816-
bottom = blob_box.bottom ();
817-
width =
818-
(inT32) floor ((FLOAT32) (blob_box.right () - blob_box.left ()));
819-
if ((inT32) floor (bottom) < min_y
820-
|| (inT32) floor (bottom) - min_y >= line_count)
821-
fprintf (stderr,
822-
"Bad y coord of bottom, " INT32FORMAT "(" INT32FORMAT ","
823-
INT32FORMAT ")\n", (inT32) floor (bottom), min_y, max_y);
813+
int32_t width = blob_box.right() - blob_box.left();
814+
index = blob_box.bottom() - min_y;
815+
ASSERT_HOST(index >= 0 && index < line_count);
824816
//count transitions
825-
index = (inT32) floor (bottom) - min_y;
826817
deltas[index] += width;
827-
if ((inT32) floor (top) < min_y
828-
|| (inT32) floor (top) - min_y >= line_count)
829-
fprintf (stderr,
830-
"Bad y coord of top, " INT32FORMAT "(" INT32FORMAT ","
831-
INT32FORMAT ")\n", (inT32) floor (top), min_y, max_y);
832-
index = (inT32) floor (top) - min_y;
818+
index = blob_box.top() - min_y;
819+
ASSERT_HOST(index >= 0 && index < line_count);
833820
deltas[index] -= width;
834821
}
835822
}

0 commit comments

Comments
 (0)