mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2024-11-27 12:49:35 +08:00
Catch nullptr in STATS::pile_count (fix isse #3694)
Add also a test case for this issue. Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
parent
7277963e11
commit
d754593a31
@ -73,6 +73,9 @@ public:
|
||||
double median() const; // get median of samples
|
||||
// Returns the count of the given value.
|
||||
int32_t pile_count(int32_t value) const {
|
||||
if (buckets_ == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
if (value <= rangemin_) {
|
||||
return buckets_[0];
|
||||
}
|
||||
|
@ -40,6 +40,13 @@ TEST_F(STATSTest, BasicStats) {
|
||||
EXPECT_EQ(12, stats_.pile_count(2));
|
||||
}
|
||||
|
||||
TEST_F(STATSTest, InitStats) {
|
||||
STATS stats;
|
||||
EXPECT_EQ(0, stats.get_total());
|
||||
EXPECT_EQ(0, stats.mode());
|
||||
EXPECT_EQ(0, stats.pile_count(2));
|
||||
}
|
||||
|
||||
// Tests the top_n_modes function.
|
||||
TEST_F(STATSTest, TopNModes) {
|
||||
std::vector<tesseract::KDPairInc<float, int> > modes;
|
||||
|
Loading…
Reference in New Issue
Block a user