diff options
author | Jorge Arellano Cid, Sebastian Geerken <devnull@localhost> | 2016-05-16 17:50:46 +0200 |
---|---|---|
committer | Jorge Arellano Cid, Sebastian Geerken <devnull@localhost> | 2016-05-16 17:50:46 +0200 |
commit | c8823f13fb56179159ff9bbc50097074f9aef50d (patch) | |
tree | b07c98ff4dec9f24f5a98496edba05d58d9c000a | |
parent | d426d90776049d94964bc0f6a45955da8eb9a0cf (diff) |
Fix segfault in OOFAwareWidget::OOFAwareWidgetIterator.
-rw-r--r-- | dw/oofawarewidget_iterator.cc | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/dw/oofawarewidget_iterator.cc b/dw/oofawarewidget_iterator.cc index afafb5d5..e427cc22 100644 --- a/dw/oofawarewidget_iterator.cc +++ b/dw/oofawarewidget_iterator.cc @@ -31,7 +31,7 @@ namespace dw { namespace oof { -// "numContentsInFlow" is passed here to avoid indirectly callin the (virtual) +// "numContentsInFlow" is passed here to avoid indirectly calling the (virtual) // method numContentsInFlow() from the constructor. OOFAwareWidget::OOFAwareWidgetIterator::OOFAwareWidgetIterator (OOFAwareWidget *widget, Content::Type mask, bool atEnd, @@ -76,7 +76,11 @@ int OOFAwareWidget::OOFAwareWidgetIterator::numParts (int sectionIndex, OOFAwareWidget *widget = (OOFAwareWidget*)getWidget(); int result; - if (sectionIndex == 0) + if (sectionIndex < 0 || sectionIndex > NUM_SECTIONS) { + DBG_OBJ_MARKF_O("iterator", 0, getWidget(), "invalid sectionIndex %d", + sectionIndex); + result = 0; + } else if (sectionIndex == 0) result = numContentsInFlow == -1 ? this->numContentsInFlow () : numContentsInFlow; else @@ -130,8 +134,9 @@ bool OOFAwareWidget::OOFAwareWidgetIterator::next () DBG_IF_RTFL { StringBuffer sb; intoStringBuffer (&sb); - DBG_OBJ_MSGF_O ("iterator", 1, getWidget (), "initial value: %s", - sb.getChars ()); + DBG_OBJ_MSGF_O ("iterator", 1, getWidget (), + "initial value: %s; sectionIndex = %d, index = %d", + sb.getChars (), sectionIndex, index); } bool r; @@ -145,7 +150,7 @@ bool OOFAwareWidget::OOFAwareWidgetIterator::next () do { index++; - if (index < numParts(sectionIndex)) + if (sectionIndex >= 0 && index < numParts(sectionIndex)) getPart (sectionIndex, index, &content); else { sectionIndex++; @@ -185,8 +190,9 @@ bool OOFAwareWidget::OOFAwareWidgetIterator::prev () DBG_IF_RTFL { StringBuffer sb; intoStringBuffer (&sb); - DBG_OBJ_MSGF_O ("iterator", 1, getWidget (), "initial value: %s", - sb.getChars ()); + DBG_OBJ_MSGF_O ("iterator", 1, getWidget (), + "initial value: %s; sectionIndex = %d, index = %d", + sb.getChars (), sectionIndex, index); } bool r; @@ -200,7 +206,8 @@ bool OOFAwareWidget::OOFAwareWidgetIterator::prev () do { index--; - if (index >= 0) + if (sectionIndex < NUM_SECTIONS && + numParts (sectionIndex) > 0 && index >= 0) getPart (sectionIndex, index, &content); else { sectionIndex--; |