Skip to content

Commit

Permalink
Merge pull request #1971 from stweil/fix
Browse files Browse the repository at this point in the history
Fix integer overflow in overlap calculation
  • Loading branch information
egorpugin authored Oct 9, 2018
2 parents ca5d285 + 7f911ac commit d93094b
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/textord/colpartition.h
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,9 @@ class ColPartition : public ELIST2_LINK {
// Returns the vertical overlap (by median) of this and other.
// WARNING! Only makes sense on horizontal partitions!
int VCoreOverlap(const ColPartition& other) const {
if (median_bottom_ == INT32_MAX || other.median_bottom_ == INT32_MAX) {
return 0;
}
return std::min(median_top_, other.median_top_) -
std::max(median_bottom_, other.median_bottom_);
}
Expand All @@ -386,6 +389,9 @@ class ColPartition : public ELIST2_LINK {
// Returns true if this and other overlap significantly vertically.
// WARNING! Only makes sense on horizontal partitions!
bool VSignificantCoreOverlap(const ColPartition& other) const {
if (median_bottom_ == INT32_MAX || other.median_bottom_ == INT32_MAX) {
return false;
}
int overlap = VCoreOverlap(other);
int height = std::min(median_top_ - median_bottom_,
other.median_top_ - other.median_bottom_);
Expand Down

0 comments on commit d93094b

Please sign in to comment.