summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-08-23 21:05:03 +0200
committerAndreas Kling <kling@serenityos.org>2022-08-23 22:39:27 +0200
commit28714deff687be9a3e0248c6073d5f7e4f488384 (patch)
tree981848296e7b63c7d4a057f55b7d9e2149dfbcb2 /Userland
parent9c1ee8cbd1473cfa1ceb613e8f90e8509f6579a6 (diff)
downloadserenity-28714deff687be9a3e0248c6073d5f7e4f488384.zip
PixelPaint: Avoid division-by-zero in HistogramWidget
This is more of a hack fix than anything else, but let's stop PixelPaint from infinite-looping in HistogramWidget::paint_event().
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Applications/PixelPaint/HistogramWidget.cpp8
1 files changed, 4 insertions, 4 deletions
diff --git a/Userland/Applications/PixelPaint/HistogramWidget.cpp b/Userland/Applications/PixelPaint/HistogramWidget.cpp
index d84cd3cf36..d8003a3482 100644
--- a/Userland/Applications/PixelPaint/HistogramWidget.cpp
+++ b/Userland/Applications/PixelPaint/HistogramWidget.cpp
@@ -89,10 +89,10 @@ ErrorOr<void> HistogramWidget::rebuild_histogram_data()
m_widget_height = height();
for (int i = 0; i < 256; i++) {
- m_data.red[i] = (static_cast<float>(m_data.red[i]) / max_color_frequency) * m_widget_height;
- m_data.green[i] = (static_cast<float>(m_data.green[i]) / max_color_frequency) * m_widget_height;
- m_data.blue[i] = (static_cast<float>(m_data.blue[i]) / max_color_frequency) * m_widget_height;
- m_data.brightness[i] = (static_cast<float>(m_data.brightness[i]) / max_brightness_frequency) * m_widget_height;
+ m_data.red[i] = m_data.red[i] != 0 ? (static_cast<float>(m_data.red[i]) / max_color_frequency) * m_widget_height : 0;
+ m_data.green[i] = m_data.green[i] != 0 ? (static_cast<float>(m_data.green[i]) / max_color_frequency) * m_widget_height : 0;
+ m_data.blue[i] = m_data.blue[i] != 0 ? (static_cast<float>(m_data.blue[i]) / max_color_frequency) * m_widget_height : 0;
+ m_data.brightness[i] = m_data.brightness[i] != 0 ? (static_cast<float>(m_data.brightness[i]) / max_brightness_frequency) * m_widget_height : 0;
}
update();