Skip to content

Commit

Permalink
Address warnings about possible division by zero from clangsa
Browse files Browse the repository at this point in the history
* The complaint in ztest_replay_write() is only possible if something
   went horribly wrong. An assertion will silence this and if it goes
   off, we will know that something is wrong.
 * The complaint in spa_estimate_metaslabs_to_flush() is not impossible,
   but seems very unlikely. We resolve this by passing the value from
   the `MIN()` that does not go to infinity when the variable is zero.

There was a third report from Clang's scan-build, but that was a
definite false positive and disappeared when checked again through
Clang's static analyzer with Z3 refution via CodeChecker.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Closes openzfs#14124
  • Loading branch information
ryao authored and andrewc12 committed Nov 11, 2022
1 parent 84dbb55 commit 59f7349
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions cmd/ztest.c
Original file line number Diff line number Diff line change
Expand Up @@ -2177,6 +2177,7 @@ ztest_replay_write(void *arg1, void *arg2, boolean_t byteswap)
* but not always, because we also want to verify correct
* behavior when the data was not recently read into cache.
*/
ASSERT(doi.doi_data_block_size);
ASSERT0(offset % doi.doi_data_block_size);
if (ztest_random(4) != 0) {
int prefetch = ztest_random(2) ?
Expand Down
3 changes: 2 additions & 1 deletion module/zfs/spa_log_spacemap.c
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,8 @@ spa_estimate_metaslabs_to_flush(spa_t *spa)
* based on the incoming rate until we exceed it.
*/
if (available_blocks >= 0 && available_txgs >= 0) {
uint64_t skip_txgs = MIN(available_txgs + 1,
uint64_t skip_txgs = (incoming == 0) ?
available_txgs + 1 : MIN(available_txgs + 1,
(available_blocks / incoming) + 1);
available_blocks -= (skip_txgs * incoming);
available_txgs -= skip_txgs;
Expand Down

0 comments on commit 59f7349

Please sign in to comment.