Commit b27e1bd6 for tesseract
commit b27e1bd66deb23c6d8db92d252c4dc45d91c7246
Author: Stefan Weil <sw@weilnetz.de>
Date: Sat Aug 15 20:22:23 2026 +0200
Fix Coverity warnings (Uninitialized pointer field, Uninitialized scalar field)
Fix CID 1586062 and CID 1586061 for elst.h and clst.h: the default
constructors of their Iterator classes only initialized the list member,
so all other pointer and scalar members remained uninitialized. Now they
are initialized to nullptr resp. false.
CID 1487954 for PAGE_RES_IT is also fixed, because its iterator members
use the elst.h Iterator.
Fix CID 1451524 for CHAR_DESC_STRUCT: the FeatureSets array was not
initialized.
Fix CID 1451515 for INT_TEMPLATES_STRUCT: the ClassPruners array was not
initialized.
Fix CID 1451508 for CLUSTER: the Left and Right pointers were not
initialized.
Fix CID 1487955 for BlamerBundle: the copy constructor left lattice_size_
uninitialized when there was no lattice data.
Fix CID 1164637 for KDPtrPair: the default constructor did not
initialize the key member.
Assisted-by: OpenCode / big-pickle (opencode)
Signed-off-by: Stefan Weil <sw@weilnetz.de>
diff --git a/src/ccstruct/blamer.h b/src/ccstruct/blamer.h
index 4d624683..ebcfe8a7 100644
--- a/src/ccstruct/blamer.h
+++ b/src/ccstruct/blamer.h
@@ -232,6 +232,7 @@ struct BlamerBundle {
lattice_size_ = other.lattice_size_;
} else {
lattice_data_ = nullptr;
+ lattice_size_ = 0;
}
}
const char *IncorrectReason() const;
diff --git a/src/ccutil/clst.h b/src/ccutil/clst.h
index 42ae0051..289a3453 100644
--- a/src/ccutil/clst.h
+++ b/src/ccutil/clst.h
@@ -146,6 +146,13 @@ public:
public:
Iterator() { // constructor
list = nullptr;
+ prev = nullptr;
+ current = nullptr;
+ next = nullptr;
+ cycle_pt = nullptr; // await explicit set
+ started_cycling = false;
+ ex_current_was_last = false;
+ ex_current_was_cycle_pt = false;
} // unassigned list
/***********************************************************************
diff --git a/src/ccutil/elst.h b/src/ccutil/elst.h
index 16dd8cc6..b540119f 100644
--- a/src/ccutil/elst.h
+++ b/src/ccutil/elst.h
@@ -209,6 +209,13 @@ public:
public:
Iterator() { // constructor
list = nullptr;
+ prev = nullptr;
+ current = nullptr;
+ next = nullptr;
+ cycle_pt = nullptr; // await explicit set
+ started_cycling = false;
+ ex_current_was_last = false;
+ ex_current_was_cycle_pt = false;
} // unassigned list
/***********************************************************************
* ELIST_ITERATOR::ELIST_ITERATOR
diff --git a/src/ccutil/kdpair.h b/src/ccutil/kdpair.h
index 4d60e454..af3b9d61 100644
--- a/src/ccutil/kdpair.h
+++ b/src/ccutil/kdpair.h
@@ -99,7 +99,7 @@ struct KDPairDec : public KDPair<Key, Data> {
template <typename Key, typename Data>
class KDPtrPair {
public:
- KDPtrPair() : data_(nullptr) {}
+ KDPtrPair() : data_(nullptr), key_{} {}
KDPtrPair(Key k, Data *d) : data_(d), key_(k) {}
// Copy constructor steals the pointer from src and nulls it in src, thereby
// moving the (single) ownership of the data.
diff --git a/src/classify/cluster.h b/src/classify/cluster.h
index 3caf7474..90c18117 100644
--- a/src/classify/cluster.h
+++ b/src/classify/cluster.h
@@ -32,7 +32,7 @@ constexpr int MAXBUCKETS = 39;
Types
----------------------------------------------------------------------*/
struct CLUSTER {
- CLUSTER(size_t n) : Mean(n) {
+ CLUSTER(size_t n) : Left(nullptr), Right(nullptr), Mean(n) {
}
~CLUSTER() {
diff --git a/src/classify/featdefs.h b/src/classify/featdefs.h
index b3f60b15..ab1ce9a5 100644
--- a/src/classify/featdefs.h
+++ b/src/classify/featdefs.h
@@ -47,9 +47,8 @@ using FEATURE_DEFS = FEATURE_DEFS_STRUCT *;
struct CHAR_DESC_STRUCT {
/// Allocate a new character description, initialize its
/// feature sets to be empty, and return it.
- CHAR_DESC_STRUCT(const FEATURE_DEFS_STRUCT &FeatureDefs) {
- NumFeatureSets = FeatureDefs.NumFeatureTypes;
- }
+ CHAR_DESC_STRUCT(const FEATURE_DEFS_STRUCT &FeatureDefs)
+ : NumFeatureSets(FeatureDefs.NumFeatureTypes), FeatureSets{} {}
/// Release the memory consumed by the specified character
/// description and all of the features in that description.
diff --git a/src/classify/intproto.cpp b/src/classify/intproto.cpp
index fbd9fe94..b199ae28 100644
--- a/src/classify/intproto.cpp
+++ b/src/classify/intproto.cpp
@@ -608,6 +608,9 @@ INT_TEMPLATES_STRUCT::INT_TEMPLATES_STRUCT() {
for (int i = 0; i < MAX_NUM_CLASSES; i++) {
ClassForClassId(this, i) = nullptr;
}
+ for (int i = 0; i < MAX_NUM_CLASS_PRUNERS; i++) {
+ ClassPruners[i] = nullptr;
+ }
}
INT_TEMPLATES_STRUCT::~INT_TEMPLATES_STRUCT() {