[kde-doc-english] [trojita] src/Gui: GUI: prevent possible division by zero

Jan Kundrát jkt at flaska.net
Wed Dec 25 21:59:22 UTC 2013


Git commit 7431bfb133f269fbb63529e25b6d443753f8bfe0 by Jan Kundrát.
Committed on 24/12/2013 at 17:33.
Pushed by jkt into branch 'master'.

GUI: prevent possible division by zero

I'm not sure how I triggered this, but I managed to do so and got SIGFPE as a
result:

 #0  0x000000000046e975 in Gui::ComposeWidget::calculateMaxVisibleRecipients (this=0x40e0090) at /home/jkt/work/prog/trojita/src/Gui/ComposeWidget.cpp:497
 #1  0x0000000000474ae4 in Gui::ComposeWidget::eventFilter (this=0x40e0090, o=<optimized out>, e=<optimized out>) at /home/jkt/work/prog/trojita/src/Gui/ComposeWidget.cpp:890
 #2  0x00007ffff6ccdbf5 in QCoreApplicationPrivate::sendThroughObjectEventFilters (this=<optimized out>, receiver=0x20e6540, event=0x7fffffffbbf0) at kernel/qcoreapplication.cpp:1059
 #3  0x00007ffff7222377 in notify_helper (e=0x7fffffffbbf0, receiver=0x20e6540, this=0x90f1b0) at kernel/qapplication.cpp:4558
 #4  QApplicationPrivate::notify_helper (this=0x90f1b0, receiver=0x20e6540, e=0x7fffffffbbf0) at kernel/qapplication.cpp:4534
 #5  0x00007ffff72277bc in QApplication::notify (this=0x7fffffffd9a0, receiver=0x20e6540, e=0x7fffffffbbf0) at kernel/qapplication.cpp:4423
 #6  0x00007ffff6ccda3c in QCoreApplication::notifyInternal (this=0x7fffffffd9a0, receiver=0x20e6540, event=0x7fffffffbbf0) at kernel/qcoreapplication.cpp:949
 #7  0x00007ffff72cee1e in sendEvent (event=0x7fffffffbbf0, receiver=0x20e6540) at ../../include/QtCore/../../src/corelib/kernel/qcoreapplication.h:231
 #8  QWidgetPrivate::setGeometry_sys (this=0x4a6c110, x=<optimized out>, y=<optimized out>, w=<optimized out>, h=<optimized out>, isMove=true) at kernel/qwidget_x11.cpp:2658
 #9  0x00007ffff727c8fd in QWidget::setGeometry (this=0x20e6540, r=...) at kernel/qwidget.cpp:6974
 #10 0x00007ffff76dd9d4 in QSplitterPrivate::setGeo (this=0x4369080, sls=0x25e9f40, p=0, s=660, allowCollapse=false) at widgets/qsplitter.cpp:750
 #11 0x00007ffff76e09e9 in QSplitterPrivate::doResize (this=0x4369080) at widgets/qsplitter.cpp:549
 #12 0x00007ffff728282e in QWidget::event (this=0x41ecce0, event=0x7fffffffc850) at kernel/qwidget.cpp:8541
 #13 0x00007ffff72223bc in notify_helper (e=0x7fffffffc850, receiver=0x41ecce0, this=0x90f1b0) at kernel/qapplication.cpp:4562
 #14 QApplicationPrivate::notify_helper (this=0x90f1b0, receiver=0x41ecce0, e=0x7fffffffc850) at kernel/qapplication.cpp:4534
 #15 0x00007ffff72277bc in QApplication::notify (this=0x7fffffffd9a0, receiver=0x41ecce0, e=0x7fffffffc850) at kernel/qapplication.cpp:4423
 #16 0x00007ffff6ccda3c in QCoreApplication::notifyInternal (this=0x7fffffffd9a0, receiver=0x41ecce0, event=0x7fffffffc850) at kernel/qcoreapplication.cpp:949
 #17 0x00007ffff72cee1e in sendEvent (event=0x7fffffffc850, receiver=0x41ecce0) at ../../include/QtCore/../../src/corelib/kernel/qcoreapplication.h:231
 #18 QWidgetPrivate::setGeometry_sys (this=0x4369080, x=<optimized out>, y=<optimized out>, w=<optimized out>, h=<optimized out>, isMove=true) at kernel/qwidget_x11.cpp:2658
 #19 0x00007ffff727c8fd in QWidget::setGeometry (this=0x41ecce0, r=...) at kernel/qwidget.cpp:6974
 #20 0x00007ffff76dd9d4 in QSplitterPrivate::setGeo (this=0x47021d0, sls=0x2fb5370, p=0, s=78, allowCollapse=false) at widgets/qsplitter.cpp:750
 #21 0x00007ffff76e09e9 in QSplitterPrivate::doResize (this=0x47021d0) at widgets/qsplitter.cpp:549
 #22 0x00007ffff76e11e0 in QSplitterPrivate::recalc (this=0x47021d0, update=true) at widgets/qsplitter.cpp:463
 #23 0x00007ffff76e13e3 in QSplitter::event (this=0x1efa310, e=0x4097960) at widgets/qsplitter.cpp:1378
 #24 0x00007ffff72223bc in notify_helper (e=0x4097960, receiver=0x1efa310, this=0x90f1b0) at kernel/qapplication.cpp:4562
 #25 QApplicationPrivate::notify_helper (this=0x90f1b0, receiver=0x1efa310, e=0x4097960) at kernel/qapplication.cpp:4534
 #26 0x00007ffff72277bc in QApplication::notify (this=0x7fffffffd9a0, receiver=0x1efa310, e=0x4097960) at kernel/qapplication.cpp:4423
 #27 0x00007ffff6ccda3c in QCoreApplication::notifyInternal (this=0x7fffffffd9a0, receiver=0x1efa310, event=0x4097960) at kernel/qcoreapplication.cpp:949
 #28 0x00007ffff6cd1c3a in sendEvent (event=0x4097960, receiver=0x1efa310) at kernel/qcoreapplication.h:231
 #29 QCoreApplicationPrivate::sendPostedEvents (receiver=0x0, event_type=<optimized out>, data=0x90ee20) at kernel/qcoreapplication.cpp:1573
 #30 0x00007ffff6d03887 in sendPostedEvents () at kernel/qcoreapplication.h:236
 #31 postEventSourceDispatch (s=<optimized out>) at kernel/qeventdispatcher_glib.cpp:280
 #32 0x00007ffff2b24ad3 in g_main_dispatch (context=0x910450) at /var/tmp/portage/dev-libs/glib-2.36.4-r1/work/glib-2.36.4/glib/gmain.c:3054
 #33 g_main_context_dispatch (context=0x910450) at /var/tmp/portage/dev-libs/glib-2.36.4-r1/work/glib-2.36.4/glib/gmain.c:3630
 #34 0x00007ffff2b24e38 in g_main_context_iterate (dispatch=1, block=<optimized out>, context=0x910450, self=<optimized out>) at /var/tmp/portage/dev-libs/glib-2.36.4-r1/work/glib-2.36.4/glib/gmain.c:3701
 #35 g_main_context_iterate (context=0x910450, block=<optimized out>, dispatch=1, self=<optimized out>) at /var/tmp/portage/dev-libs/glib-2.36.4-r1/work/glib-2.36.4/glib/gmain.c:3638
 #36 0x00007ffff2b24f2c in g_main_context_iteration (context=0x910450, may_block=1) at /var/tmp/portage/dev-libs/glib-2.36.4-r1/work/glib-2.36.4/glib/gmain.c:3762
 #37 0x00007ffff6d03d3f in QEventDispatcherGlib::processEvents (this=0x90c7e0, flags=...) at kernel/qeventdispatcher_glib.cpp:425
 #38 0x00007ffff72dd4c6 in QGuiEventDispatcherGlib::processEvents (this=<optimized out>, flags=...) at kernel/qguieventdispatcher_glib.cpp:204
 #39 0x00007ffff6ccbf12 in QEventLoop::processEvents (this=<optimized out>, flags=...) at kernel/qeventloop.cpp:149
 #40 0x00007ffff6ccc287 in QEventLoop::exec (this=0x7fffffffd540, flags=...) at kernel/qeventloop.cpp:204
 #41 0x00007ffff6cd1f95 in QCoreApplication::exec () at kernel/qcoreapplication.cpp:1221
 #42 0x000000000043a317 in main (argc=1, argv=<optimized out>) at /home/jkt/work/prog/trojita/src/Gui/main.cpp:86

REVIEW: 114665

M  +5    -1    src/Gui/ComposeWidget.cpp

http://commits.kde.org/trojita/7431bfb133f269fbb63529e25b6d443753f8bfe0

diff --git a/src/Gui/ComposeWidget.cpp b/src/Gui/ComposeWidget.cpp
index fe98818..60dddc5 100644
--- a/src/Gui/ComposeWidget.cpp
+++ b/src/Gui/ComposeWidget.cpp
@@ -494,7 +494,11 @@ void ComposeWidget::calculateMaxVisibleRecipients()
                        (subjectHeight + spacing) - // for the subject
                        bottom - // layout bottom padding
                        2; // extra pixels padding to detect that the user wants to shrink
-    m_maxVisibleRecipients = height / (itemHeight + spacing);
+    if (itemHeight + spacing == 0) {
+        m_maxVisibleRecipients = MIN_MAX_VISIBLE_RECIPIENTS;
+    } else {
+        m_maxVisibleRecipients = height / (itemHeight + spacing);
+    }
     if (m_maxVisibleRecipients < MIN_MAX_VISIBLE_RECIPIENTS)
         m_maxVisibleRecipients = MIN_MAX_VISIBLE_RECIPIENTS; // allow up to 4 recipients w/o need for a sliding
     if (oldMaxVisibleRecipients != m_maxVisibleRecipients) {


More information about the kde-doc-english mailing list