Skip to content

Commit

Permalink
Add assert
Browse files Browse the repository at this point in the history
  • Loading branch information
shosseinimotlagh committed Sep 19, 2024
1 parent 1fbb18d commit 00a9874
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/engine/blkalloc/blk.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ struct BlkId {
static constexpr uint64_t s_chunk_num_mask{(static_cast< uint64_t >(1) << CHUNK_NUM_BITS) - 1};

public:
[[nodiscard]] static constexpr blk_count_t max_blks_in_op() { return (1 << NBLKS_BITS); }
[[nodiscard]] static constexpr blk_count_t max_blks_in_op() {
static_assert(NBLKS_BITS <= std::numeric_limits< blk_count_t >::digits,
"NBLKS_BITS is too large and may cause overflow in blk_count_t");
return (1 << NBLKS_BITS);
}
[[nodiscard]] static constexpr uint64_t max_id_int() {
return (1ull << (BLK_NUM_BITS + NBLKS_BITS + CHUNK_NUM_BITS)) - 1;
}
Expand Down
2 changes: 1 addition & 1 deletion src/engine/blkstore/blkstore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ class BlkStore {
uint32_t nblks{static_cast< uint32_t >(size / m_pagesz)};
if (nblks <= BlkId::max_blks_in_op()) {
auto max_val = std::numeric_limits< blk_count_t >::max();
HS_DBG_ASSERT_LE(nblks, max_val, "max_blks_in_op must be less than {}", max_val);
HS_DBG_ASSERT_LE(nblks, max_val, "nblks must be less than {}", max_val);
return (m_vdev.alloc_blk(static_cast< blk_count_t >(nblks), hints, out_blkid));
} else {
while (nblks != 0) {
Expand Down

0 comments on commit 00a9874

Please sign in to comment.