From bff683416c73329eb91bdb0bc282f4022c9fec7e Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Fri, 8 Jul 2016 14:41:49 +0200 Subject: QDateTimeEditPrivate:: only ask for fieldInfo() if section index is real On construction, currentSectionIndex has the fake value FirstSectionIndex, which upsets fieldInfo(), leading to a qWarning(). Make interpret(), when deciding whether to delegate to base or handle the value itself, treat fake index value as an invalid state. Task-number: QTBUG-54654 Change-Id: I6d0f71874839abfafcbfaaa0018362288f32a3cd Reviewed-by: Andy Shaw --- src/widgets/widgets/qdatetimeedit.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/widgets/widgets') diff --git a/src/widgets/widgets/qdatetimeedit.cpp b/src/widgets/widgets/qdatetimeedit.cpp index 96a37197e9..98b0489dfc 100644 --- a/src/widgets/widgets/qdatetimeedit.cpp +++ b/src/widgets/widgets/qdatetimeedit.cpp @@ -2344,7 +2344,9 @@ void QDateTimeEditPrivate::interpret(EmitPolicy ep) const QValidator::State state = q->validate(tmp, pos); if (state != QValidator::Acceptable && correctionMode == QAbstractSpinBox::CorrectToPreviousValue - && (state == QValidator::Invalid || !(fieldInfo(currentSectionIndex) & AllowPartial))) { + && (state == QValidator::Invalid + || currentSectionIndex < 0 + || !(fieldInfo(currentSectionIndex) & AllowPartial))) { setValue(value, ep); updateTimeSpec(); } else { -- cgit v1.2.3 From eec2d5e68af7b65342e4e5a95e47481a483be67e Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sat, 8 Oct 2016 00:48:02 +0200 Subject: QCalendarWidget: fix a missing break statement GCC 7 warns about implicit fall-throughs, and here it looks like a break was indeed missing. It surely isn't catastrophic that the other update code is executed, too, but it's also useless. Turns out Coverity knew it all along... Coverity-Id: 11162 Change-Id: I88fc0174a66ec337b2d93c006e70be8d5f3bbc33 Reviewed-by: Edward Welbourne --- src/widgets/widgets/qcalendarwidget.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/widgets/widgets') diff --git a/src/widgets/widgets/qcalendarwidget.cpp b/src/widgets/widgets/qcalendarwidget.cpp index 89cde851e5..3823b9c10f 100644 --- a/src/widgets/widgets/qcalendarwidget.cpp +++ b/src/widgets/widgets/qcalendarwidget.cpp @@ -2994,6 +2994,7 @@ bool QCalendarWidget::event(QEvent *event) switch (event->type()) { case QEvent::LayoutDirectionChange: d->updateButtonIcons(); + break; case QEvent::LocaleChange: d->m_model->setFirstColumnDay(locale().firstDayOfWeek()); d->cachedSizeHint = QSize(); -- cgit v1.2.3 From 2ecd95bbe907cc9199773bb7930f781058735e1c Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 10 Oct 2016 20:47:40 +0200 Subject: QCalendarWidget: fix misleading if-else cascade in QCalendarDayValidator::text() By the time we hit the last else, its if condition is trivially true, so don't check it (but leave it as a comment). Consequently, remove the trailing (dead) return of a default- constructed QString. Coverity-Id: 62766 Change-Id: I47e1a49f40e6ec95d29c5052c78bfadb63af3b84 Reviewed-by: Edward Welbourne --- src/widgets/widgets/qcalendarwidget.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/widgets/widgets') diff --git a/src/widgets/widgets/qcalendarwidget.cpp b/src/widgets/widgets/qcalendarwidget.cpp index 3823b9c10f..7895dc04d9 100644 --- a/src/widgets/widgets/qcalendarwidget.cpp +++ b/src/widgets/widgets/qcalendarwidget.cpp @@ -205,10 +205,9 @@ QString QCalendarDayValidator::text(const QDate &date, int repeat) const return formatNumber(date.day(), 2); } else if (repeat == 3) { return m_locale.dayName(date.dayOfWeek(), QLocale::ShortFormat); - } else if (repeat >= 4) { + } else /* repeat >= 4 */ { return m_locale.dayName(date.dayOfWeek(), QLocale::LongFormat); } - return QString(); } ////////////////////////////////// -- cgit v1.2.3 From c34c8a564ef029144db6d2be256de7e46f91199a Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 10 Oct 2016 21:43:05 +0200 Subject: QComboBox: add missing break in switch in keyPressEvent() If the Key_Space case falls through, it does because !d->lineEdit, which makes the following case dead code, because it is guarded by the same condition. Fix by adding the break, which ensures that if those two cases ever diverge, the code stays working by intention, not chance. Independently discovered by GCC 7 and Coverity. Coverity-Id: 11157 Change-Id: Id14114b4157549d0f6fa036e8aa2bf0fa5a863cf Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/widgets/widgets/qcombobox.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/widgets/widgets') diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp index 181671c493..450c27d573 100644 --- a/src/widgets/widgets/qcombobox.cpp +++ b/src/widgets/widgets/qcombobox.cpp @@ -3160,6 +3160,7 @@ void QComboBox::keyPressEvent(QKeyEvent *e) showPopup(); return; } + break; case Qt::Key_Enter: case Qt::Key_Return: case Qt::Key_Escape: -- cgit v1.2.3 From de48fd192b7973c4849ec79bce4cd491b5e8550f Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 10 Oct 2016 21:02:16 +0200 Subject: QToolBarAreaLayoutInfo: add missing break statements in switch in distance() A fall-through here is logically non-sensical, because of symmetry (or lack thereof). Thus, a break must have been intended. Add it. While we're at it, also replace the default case label with the non-functional enum value QInternal::DockCount, so that -Wswitch can warn us if ever there should be a new DockPosition. Found independently by both GCC 7 and Coverity. Coverity-Id: 11145 Coverity-Id: 11146 Coverity-Id: 11147 Change-Id: I6bb31c1517e40f0cb06ceaee5aeb6fa78b84a523 Reviewed-by: Edward Welbourne --- src/widgets/widgets/qtoolbararealayout.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/widgets/widgets') diff --git a/src/widgets/widgets/qtoolbararealayout.cpp b/src/widgets/widgets/qtoolbararealayout.cpp index 16b1115dd6..f42c1f0ed9 100644 --- a/src/widgets/widgets/qtoolbararealayout.cpp +++ b/src/widgets/widgets/qtoolbararealayout.cpp @@ -598,16 +598,21 @@ int QToolBarAreaLayoutInfo::distance(const QPoint &pos) const case QInternal::LeftDock: if (pos.y() < rect.bottom()) return pos.x() - rect.right(); + break; case QInternal::RightDock: if (pos.y() < rect.bottom()) return rect.left() - pos.x(); + break; case QInternal::TopDock: if (pos.x() < rect.right()) return pos.y() - rect.bottom(); + break; case QInternal::BottomDock: if (pos.x() < rect.right()) return rect.top() - pos.y(); - default: + break; + + case QInternal::DockCount: break; } return -1; -- cgit v1.2.3