The following issues were found

unittest/fuzzers/fuzzer-api.cpp
1 issues
getenv - Environment variables are untrustable input if they can be set by an attacker. They can have any content and length, and the same variable can be set more than once
Security

Line: 47 Column: 12 CWE codes: 807 20
Suggestion: Check environment variables carefully before using them

              static tesseract::TessBaseAPI *api = nullptr;

extern "C" int LLVMFuzzerInitialize(int * /*pArgc*/, char ***pArgv) {
  if (std::getenv("TESSDATA_PREFIX") == nullptr) {
    std::string binary_path = *pArgv[0];
    const std::string filepath = dirname(&binary_path[0]);

    const std::string tessdata_path = filepath + "/" + "tessdata";
    if (setenv("TESSDATA_PREFIX", tessdata_path.c_str(), 1) != 0) {

            

Reported by FlawFinder.

unittest/heap_test.cc
1 issues
syntax error
Error

Line: 81

              
// Tests that a sort using a GenericHeap matches the result of a sort using
// a KDVector.
TEST_F(HeapTest, SortTest) {
  GenericHeap<IntKDPair> heap;
  EXPECT_TRUE(heap.empty());
  KDVector v;
  EXPECT_EQ(heap.size(), v.size());
  // Push the test data onto both the heap and the KDVector.

            

Reported by Cppcheck.

unittest/intfeaturemap_test.cc
1 issues
syntax error
Error

Line: 42

              };

// Tests the IntFeatureMap and implicitly the IntFeatureSpace underneath.
TEST_F(IntFeatureMapTest, Exhaustive) {
#ifdef DISABLED_LEGACY_ENGINE
  // Skip test because IntFeatureSpace is missing.
  GTEST_SKIP();
#else
  IntFeatureSpace space;

            

Reported by Cppcheck.

unittest/intsimdmatrix_test.cc
1 issues
syntax error
Error

Line: 105

              };

// Test the C++ implementation without SIMD.
TEST_F(IntSimdMatrixTest, C) {
  static const IntSimdMatrix matrix = {nullptr, 1, 1, 1, 1};
  ExpectEqualResults(matrix);
}

// Tests that the SSE implementation gets the same result as the vanilla.

            

Reported by Cppcheck.

unittest/lang_model_test.cc
1 issues
syntax error
Error

Line: 32

              // the extent that an LSTMTrainer can be initialized with the result, and it
// can encode strings. More importantly, the test verifies that adding an extra
// character to the unicharset does not change the encoding of strings.
TEST(LangModelTest, AddACharacter) {
  constexpr char kTestString[] = "Simple ASCII string to encode !@#$%&";
  constexpr char kTestStringRupees[] = "ASCII string with Rupee symbol ₹";
  // Setup the arguments.
  std::string script_dir = LANGDATA_DIR;
  std::string eng_dir = file::JoinPath(script_dir, "eng");

            

Reported by Cppcheck.

unittest/layout_test.cc
1 issues
syntax error
Error

Line: 191

              };

// Tests that array sizes match their intended size.
TEST_F(LayoutTest, ArraySizeTest) {
  int size = 0;
  for (size = 0; kPolyBlockNames[size][0] != '\0'; ++size) {
    ;
  }
  EXPECT_EQ(size, PT_COUNT);

            

Reported by Cppcheck.

unittest/ligature_table_test.cc
1 issues
syntax error
Error

Line: 52

                LigatureTable *lig_table_;
};

TEST_F(LigatureTableTest, DoesFillLigatureTables) {
  EXPECT_GT(lig_table_->norm_to_lig_table().size(), 0);
  EXPECT_GT(lig_table_->lig_to_norm_table().size(), 0);
}

TEST_F(LigatureTableTest, DoesAddLigatures) {

            

Reported by Cppcheck.

unittest/linlsq_test.cc
1 issues
syntax error
Error

Line: 68

              };

// Tests a simple baseline-style normalization.
TEST_F(LLSQTest, BasicLines) {
  LLSQ llsq;
  llsq.add(1.0, 1.0);
  llsq.add(2.0, 2.0);
  ExpectCorrectLine(llsq, 1.0, 0.0, 0.0, 1.0, 1e-6);
  float half_root_2 = sqrt(2.0) / 2.0f;

            

Reported by Cppcheck.

unittest/list_test.cc
1 issues
syntax error
Error

Line: 81

                // TODO: add more tests for CLIST
}

TEST_F(ListTest, TestELIST) {
  Elst_LIST list;
  EXPECT_TRUE(list.empty());
  EXPECT_EQ(list.length(), 0);
  auto it = ELIST_ITERATOR(&list);
  for (unsigned i = 0; i < ListSize; i++) {

            

Reported by Cppcheck.

unittest/loadlang_test.cc
1 issues
syntax error
Error

Line: 49

              
class LoadLanguage : public QuickTest, public ::testing::WithParamInterface<const char *> {};

TEST_P(LoadLanguage, afr) {
  LangLoader("afr", GetParam());
}
TEST_P(LoadLanguage, amh) {
  LangLoader("amh", GetParam());
}

            

Reported by Cppcheck.