From f0b8d3423083d865f1ccb34e297f904b1be01e92 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Fri, 11 Apr 2025 01:46:00 -0500 Subject: [PATCH] scripts: maps: Fixed divide-by-zero when packing blocks into small maps This can be hit when dealing with very small maps, which is common since we're rendering to the terminal. Not crashing here at least allows the header/usage string to be shown. --- scripts/dbgbmap.py | 6 +++--- scripts/dbgbmapd3.py | 6 +++--- scripts/tracebd.py | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/scripts/dbgbmap.py b/scripts/dbgbmap.py index 9eb7b3fd..cbf0d82c 100755 --- a/scripts/dbgbmap.py +++ b/scripts/dbgbmap.py @@ -4598,11 +4598,11 @@ def main_(ring, disk, mroots=None, *, # well for things that are often powers-of-two block_cols_ = 1 block_rows_ = len(bmap) - while (abs(((canvas.width/(block_cols_ * 2)) - / (canvas.height/mt.ceil(block_rows_ / 2))) + while (abs(((canvas.width/(block_cols_*2)) + / max(canvas.height/mt.ceil(block_rows_/2), 1)) - block_ratio) < abs(((canvas.width/block_cols_) - / (canvas.height/block_rows_))) + / max(canvas.height/block_rows_, 1))) - block_ratio): block_cols_ *= 2 block_rows_ = mt.ceil(block_rows_ / 2) diff --git a/scripts/dbgbmapd3.py b/scripts/dbgbmapd3.py index 795fd3b6..352ec076 100755 --- a/scripts/dbgbmapd3.py +++ b/scripts/dbgbmapd3.py @@ -4918,11 +4918,11 @@ def main(disk, output, mroots=None, *, # well for things that are often powers-of-two block_cols_ = 1 block_rows_ = len(bmap) - while (abs(((width__/(block_cols_ * 2)) - / (height__/mt.ceil(block_rows_ / 2))) + while (abs(((width__/(block_cols_*2)) + / max(height__/mt.ceil(block_rows_/2), 1)) - block_ratio) < abs(((width__/block_cols_) - / (height__/block_rows_))) + / max(height__/block_rows_, 1))) - block_ratio): block_cols_ *= 2 block_rows_ = mt.ceil(block_rows_ / 2) diff --git a/scripts/tracebd.py b/scripts/tracebd.py index d5789836..4aa3aefb 100755 --- a/scripts/tracebd.py +++ b/scripts/tracebd.py @@ -1794,11 +1794,11 @@ def main(path='-', *, # well for things that are often powers-of-two block_cols_ = 1 block_rows_ = len(bmap) - while (abs(((canvas.width/(block_cols_ * 2)) - / (canvas.height/mt.ceil(block_rows_ / 2))) + while (abs(((canvas.width/(block_cols_*2)) + / max(canvas.height/mt.ceil(block_rows_/2), 1)) - block_ratio) < abs(((canvas.width/block_cols_) - / (canvas.height/block_rows_))) + / max(canvas.height/block_rows_, 1))) - block_ratio): block_cols_ *= 2 block_rows_ = mt.ceil(block_rows_ / 2)