The following issues were found

src/training/unicharset/lang_model_helpers.cpp
1 issues
memcpy - Does not check for buffer overflows when copying to destination
Security

Line: 128 Column: 3 CWE codes: 120
Suggestion: Make sure destination can always hold the source data

                traineddata->OverwriteEntry(TESSDATA_LSTM_RECODER, &recoder_data[0], recoder_data.size());
  std::string encoding = recoder.GetEncodingAsString(unicharset);
  recoder_data.resize(encoding.length(), 0);
  memcpy(&recoder_data[0], &encoding[0], encoding.length());
  std::string suffix;
  suffix += ".charset_size=" + std::to_string(recoder.code_range());
  suffix += ".txt";
  return WriteFile(output_dir, lang, suffix.c_str(), recoder_data, writer);
}

            

Reported by FlawFinder.

src/viewer/svpaint.cpp
1 issues
atoi - Unless checked, the resulting number can exceed the expected range
Security

Line: 108 Column: 35 CWE codes: 190
Suggestion: If source untrusted, check both minimum and maximum, even if the input had no minus sign (large numbers can roll over into negative number; consider saving to an unsigned value if that is intended)

              void SVPaint::PopupHandler(const SVEvent *sv_event) {
  // Since we only have the RGB values as popup items,
  // we take a shortcut to not bloat up code:
  rgb[sv_event->command_id - 1] = atoi(sv_event->parameter);
  window_->Pen(rgb[0], rgb[1], rgb[2]);
}

// Takes care of the SVET_MENU events.
// In our case, we change either the click_mode_ (commands 1-3)

            

Reported by FlawFinder.

unittest/apiexample_test.cc
1 issues
syntax error
Error

Line: 84

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

TEST_P(MatchGroundTruth, FastPhototestOCR) {
  OCRTester(TESTING_DIR "/phototest.tif", TESTING_DIR "/phototest.txt", TESSDATA_DIR "_fast",
            GetParam());
}

TEST_P(MatchGroundTruth, BestPhototestOCR) {

            

Reported by Cppcheck.

unittest/applybox_test.cc
1 issues
syntax error
Error

Line: 110

              };

// Tests character-level applyboxes on normal Times New Roman.
TEST_F(ApplyBoxTest, TimesCharLevel) {
  VerifyBoxesAndText("trainingtimes.tif", kTruthTextWords, "trainingtimes.box", false);
}

// Tests character-level applyboxes on italic Times New Roman.
TEST_F(ApplyBoxTest, ItalicCharLevel) {

            

Reported by Cppcheck.

unittest/baseapi_test.cc
1 issues
syntax error
Error

Line: 66

              };

// Test static TessBaseAPI (like it is used by tesserocr).
TEST_F(TesseractTest, StaticTessBaseAPI) {
  static tesseract::TessBaseAPI api;
  api.End();
}

// Tests that Tesseract gets exactly the right answer on phototest.

            

Reported by Cppcheck.

unittest/baseapi_thread_test.cc
1 issues
syntax error
Error

Line: 179

              
// Check that Tesseract/Cube produce the correct results in single-threaded
// operation. If not, it is pointless to run the real multi-threaded tests.
TEST_F(BaseapiThreadTest, TestBasicSanity) {
  for (int i = 0; i < num_langs_; ++i) {
    TessBaseAPI tess;
    InitTessInstance(&tess, langs_[i]);
    std::string ocr_text;
    GetCleanedText(&tess, pix_[i], ocr_text);

            

Reported by Cppcheck.

unittest/colpartition_test.cc
1 issues
syntax error
Error

Line: 35

                void TearDown() override {}
};

TEST_F(ColPartitionTest, IsInSameColumnAsReflexive) {
  TestableColPartition a, b;
  a.SetColumnRange(1, 2);
  b.SetColumnRange(3, 3);

  EXPECT_TRUE(a.IsInSameColumnAs(a));

            

Reported by Cppcheck.

unittest/commandlineflags_test.cc
1 issues
syntax error
Error

Line: 44

                }
};

TEST_F(CommandlineflagsTest, RemoveFlags) {
  const char *const_argv[] = {"Progname", "--foo_int", "3", "file1.h", "file2.h"};
  int argc = countof(const_argv);
  char **argv = const_cast<char **>(const_argv);
  tesseract::ParseCommandLineFlags(argv[0], &argc, &argv, true);


            

Reported by Cppcheck.

unittest/denorm_test.cc
1 issues
syntax error
Error

Line: 51

              };

// Tests a simple baseline-style normalization.
TEST_F(DENORMTest, NoRotations) {
  DENORM denorm;
  denorm.SetupNormalization(nullptr, nullptr, nullptr, 1000.0f, 2000.0f, 2.0f, 3.0f, 0.0f,
                            static_cast<float>(kBlnBaselineOffset));
  TPOINT pt1(1100, 2000);
  TPOINT result1(200, kBlnBaselineOffset);

            

Reported by Cppcheck.

unittest/equationdetect_test.cc
1 issues
syntax error
Error

Line: 180

                }
};

TEST_F(EquationFinderTest, IdentifySpecialText) {
#if !ENABLE_IdentifySpecialText_TEST
  GTEST_SKIP();
#else // TODO: missing equ_gt1.tif
  // Load Image.
  std::string imagefile = file::JoinPath(testdata_dir_, "equ_gt1.tif");

            

Reported by Cppcheck.