From 7b8fd2d81ad80a73564fc9fbb779f47568f12652 Mon Sep 17 00:00:00 2001 From: Mathias Gumz Date: Sat, 10 Jan 2015 22:44:37 +0100 Subject: Fix bug: integer underflow in startup phase When fluxbox comes up some of it's drawables span a 1x1 area. Subtracting from such small numbers bigger ones always lead to massive problems when 'unsigned int' are involved: 'button_width' is an unsigned int of '1' (this might be caused by another issue or on purpose, anyway), subtracting -10 or any other number should result in something < 0 when in reality an integer underflow happen: max_width is now MAX_INT-something big. This makes fluxbox crash under certain circumstances. This fixes bug #1116. --- src/FbTk/TextButton.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/FbTk/TextButton.cc b/src/FbTk/TextButton.cc index 611580c..a177f25 100644 --- a/src/FbTk/TextButton.cc +++ b/src/FbTk/TextButton.cc @@ -143,11 +143,17 @@ void TextButton::drawText(int x_offset, int y_offset, FbDrawable *drawable) { unsigned int textlen = visual.size(); unsigned int button_width = width(); unsigned int button_height = height(); + const int max_width = static_cast(button_width) - x_offset - + m_left_padding - m_right_padding; + + if (max_width <= bevel()) { + return; + } translateSize(m_orientation, button_width, button_height); // horizontal alignment, cut off text if needed - int align_x = FbTk::doAlignment(button_width - x_offset - m_left_padding - m_right_padding, + int align_x = FbTk::doAlignment(max_width, bevel(), justify(), font(), visual.data(), visual.size(), textlen); // return new text len -- cgit v0.11.2