Skip to content

Commit

Permalink
Fix stringop-overflow warning in Scratch.h (facebookincubator#9526)
Browse files Browse the repository at this point in the history
Summary:
Fixes: facebookincubator#9525

Compiler generates stringop-overflow warning because it fails to infer that
`if (newCapacity > capacity_)` would be false when `newCapacity` is zero.

Add hint to prevent the compiler from generating the stringop-overflow
warning when 'newCapacity' is 0.

Pull Request resolved: facebookincubator#9526

Reviewed By: xiaoxmeng

Differential Revision: D56308183

Pulled By: Yuhta

fbshipit-source-id: a41f0060c11ad906c1e91ff3469361e837d5d00d
  • Loading branch information
zhli1142015 authored and facebook-github-bot committed Apr 18, 2024
1 parent 8fb0c9c commit e18a4cf
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions velox/common/base/Scratch.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ class Scratch {
for (auto i = newCapacity; i < fill_; ++i) {
std::destroy_at(&items_[i]);
}
// Add hint to prevent the compiler from generating the
// stringop-overflow warning when 'newCapacity' is 0.
folly::assume(capacity_ >= 0);
if (newCapacity > capacity_) {
Item* newItems =
reinterpret_cast<Item*>(::malloc(sizeof(Item) * newCapacity));
Expand Down

0 comments on commit e18a4cf

Please sign in to comment.