Commit 3673cd2f for tesseract

commit 3673cd2f84cc6954256560c583523f79162a96a5
Author: Stefan Weil <sw@weilnetz.de>
Date:   Fri Nov 27 09:28:29 2026 +0100

    Fix the open CodeQL alerts

    The code scanning of the repository reports nine alerts since 2021.
    None of them can go wrong with real data, but the code is clearer
    without the mixed types.

    cpp/comparison-with-wider-type (blobbox.cpp, blkocc.cpp, fpchop.cpp):
    loops over the steps of an outline compared an int16_t index with the
    int32_t result of C_OUTLINE::pathlength(). The step count is stored
    in an int16_t and limited by kMaxOutlineLength, so the index could
    not wrap. Use int32_t for the index.

    cpp/integer-multiplication-cast-to-long (quspline.cpp): the constant
    of an extrapolated segment was computed from a float product which
    was converted to double afterwards. Multiply in double.

    cpp/integer-multiplication-cast-to-long (intsimdmatrix.cpp): the size
    of the reshaped weight matrix was an int product which was converted
    to size_t afterwards. Convert before the multiplication.

    Text and hOCR output of 38 test images and 204 newspaper pages did
    not change.

    Assisted-by: Claude Fable 5.2 (Anthropic)
    Signed-off-by: Stefan Weil <sw@weilnetz.de>

diff --git a/src/arch/intsimdmatrix.cpp b/src/arch/intsimdmatrix.cpp
index 9929e8cc..b72e6f24 100644
--- a/src/arch/intsimdmatrix.cpp
+++ b/src/arch/intsimdmatrix.cpp
@@ -32,7 +32,7 @@ void IntSimdMatrix::Init(const GENERIC_2D_ARRAY<int8_t> &w, std::vector<int8_t>
   int rounded_num_in = Roundup(num_in, num_inputs_per_group_);
   rounded_num_out = RoundOutputs(num_out);
   // Add the bias and compute the required size.
-  shaped_w.resize((rounded_num_in + 1) * rounded_num_out, 0);
+  shaped_w.resize(static_cast<size_t>(rounded_num_in + 1) * rounded_num_out, 0);
   int shaped_index = 0;
   int output = 0;
   // Each number of registers needs a different format! Iterates over the
diff --git a/src/ccstruct/blobbox.cpp b/src/ccstruct/blobbox.cpp
index 7b657fd9..a9621007 100644
--- a/src/ccstruct/blobbox.cpp
+++ b/src/ccstruct/blobbox.cpp
@@ -506,7 +506,7 @@ void find_cblob_limits( // get y limits
     FCOORD rotation, // for landscape
     float &ymin,     // output y limits
     float &ymax) {
-  int16_t stepindex;  // current point
+  int32_t stepindex;  // current point
   ICOORD pos;         // current coords
   ICOORD vec;         // rotated step
   C_OUTLINE *outline; // current outline
@@ -544,7 +544,7 @@ void find_cblob_vlimits( // get y limits
     float rightx,
     float &ymin, // output y limits
     float &ymax) {
-  int16_t stepindex;  // current point
+  int32_t stepindex;  // current point
   ICOORD pos;         // current coords
   ICOORD vec;         // rotated step
   C_OUTLINE *outline; // current outline
@@ -580,7 +580,7 @@ void find_cblob_hlimits( // get x limits
     float topy,
     float &xmin, // output x limits
     float &xmax) {
-  int16_t stepindex;  // current point
+  int32_t stepindex;  // current point
   ICOORD pos;         // current coords
   ICOORD vec;         // rotated step
   C_OUTLINE *outline; // current outline
@@ -892,7 +892,7 @@ void vertical_coutline_projection( // project outlines
   ICOORD pos;        // current point
   ICOORD step;       // edge step
   int32_t length;    // of outline
-  int16_t stepindex; // current step
+  int32_t stepindex; // current step
   C_OUTLINE_IT out_it = outline->child();

   pos = outline->start_pos();
diff --git a/src/ccstruct/quspline.cpp b/src/ccstruct/quspline.cpp
index 6b341f56..7342fae4 100644
--- a/src/ccstruct/quspline.cpp
+++ b/src/ccstruct/quspline.cpp
@@ -331,7 +331,7 @@ void QSPLINE::extrapolate( // linear extrapolation
     xstarts[0] = xmin;
     quads[0].a = 0;
     quads[0].b = gradient;
-    quads[0].c = y(xcoords[0]) - quads[0].b * xcoords[0];
+    quads[0].c = y(xcoords[0]) - static_cast<double>(quads[0].b) * xcoords[0];
     dest_segment = 1;
   } else {
     dest_segment = 0;
@@ -345,7 +345,8 @@ void QSPLINE::extrapolate( // linear extrapolation
   if (xmax > xcoords[segments]) {
     quads[dest_segment].a = 0;
     quads[dest_segment].b = gradient;
-    quads[dest_segment].c = y(xcoords[segments]) - quads[dest_segment].b * xcoords[segments];
+    quads[dest_segment].c =
+        y(xcoords[segments]) - static_cast<double>(quads[dest_segment].b) * xcoords[segments];
     dest_segment++;
     xstarts[dest_segment] = xmax + 1;
   }
diff --git a/src/textord/blkocc.cpp b/src/textord/blkocc.cpp
index 81f9c5cf..332739c5 100644
--- a/src/textord/blkocc.cpp
+++ b/src/textord/blkocc.cpp
@@ -136,7 +136,7 @@ static void horizontal_coutline_projection( // project outlines
   ICOORD pos;        // current point
   ICOORD step;       // edge step
   int32_t length;    // of outline
-  int16_t stepindex; // current step
+  int32_t stepindex; // current step
   C_OUTLINE_IT out_it = outline->child();

   pos = outline->start_pos();
diff --git a/src/textord/fpchop.cpp b/src/textord/fpchop.cpp
index 5611d2ab..516095e3 100644
--- a/src/textord/fpchop.cpp
+++ b/src/textord/fpchop.cpp
@@ -415,7 +415,7 @@ static bool fixed_chop_coutline(     // chop the outline
   int16_t left_edge;       // of outline
   int16_t startindex;      // in first fragment
   int32_t length;          // of outline
-  int16_t stepindex;       // into outline
+  int32_t stepindex;       // into outline
   int16_t head_index;      // start of fragment
   ICOORD head_pos;         // start of fragment
   int16_t tail_index;      // end of fragment
@@ -432,7 +432,7 @@ static bool fixed_chop_coutline(     // chop the outline
   for (stepindex = 0; stepindex < length; stepindex++) {
     if (pos.x() < left_edge) {
       left_edge = pos.x();
-      tail_index = stepindex;
+      tail_index = static_cast<int16_t>(stepindex);
       tail_pos = pos;
     }
     pos += srcline->step(stepindex);