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.
This commit is contained in:
Mathias Gumz 2015-01-10 22:44:37 +01:00
parent d8c11d0852
commit 7b8fd2d81a

View file

@ -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<int>(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