From df4cbaf8dc59a5c62ad82a56de8e3596bfecebcd Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Fri, 18 Sep 2020 11:46:55 +0200 Subject: Assert some conditions instead of testing for them MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In one case, handle an error by an early return so that we can do so. Change-Id: If98eaaf2dfd47c1df1d09497fcc3e9ab784dc6df Reviewed-by: MÃ¥rten Nordheim --- src/corelib/time/qdatetimeparser.cpp | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/corelib/time/qdatetimeparser.cpp b/src/corelib/time/qdatetimeparser.cpp index 5e072b10ca..8ab6f73a31 100644 --- a/src/corelib/time/qdatetimeparser.cpp +++ b/src/corelib/time/qdatetimeparser.cpp @@ -733,11 +733,8 @@ QDateTimeParser::parseSection(const QDateTime ¤tValue, int sectionIndex, { ParsedSection result; // initially Invalid const SectionNode &sn = sectionNode(sectionIndex); - if (sn.type & Internal) { - qWarning("QDateTimeParser::parseSection Internal error (%ls %d)", - qUtf16Printable(sn.name()), sectionIndex); - return result; - } + Q_ASSERT_X(!(sn.type & Internal), + "QDateTimeParser::parseSection", "Internal error"); const int sectionmaxsize = sectionMaxSize(sectionIndex); QStringView sectionTextRef = QStringView{*text}.mid(offset, sectionmaxsize); @@ -1226,27 +1223,23 @@ QDateTimeParser::scanString(const QDateTime &defaultValue, default: qWarning("QDateTimeParser::parse Internal error (%ls)", qUtf16Printable(sn.name())); - break; + return StateNode(); } + Q_ASSERT(current); + Q_ASSERT(sect.state != Invalid); if (sect.used > 0) pos += sect.used; QDTPDEBUG << index << sn.name() << "is set to" << pos << "state is" << stateName(state); - if (!current) { - qWarning("QDateTimeParser::parse Internal error 2"); - return StateNode(); - } if (isSet & sn.type && *current != sect.value) { QDTPDEBUG << "CONFLICT " << sn.name() << *current << sect.value; conflicts = true; - if (index != currentSectionIndex || sect.state == Invalid) { + if (index != currentSectionIndex) continue; - } } - if (sect.state != Invalid) - *current = sect.value; + *current = sect.value; // Record the present section: isSet |= sn.type; -- cgit v1.2.3