From 4b395965129b91aa2c616539cc5500393063c8e1 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 4 Sep 2023 18:49:12 +0200 Subject: [PATCH] Minor tidies in example's XML converter Make a local variable more local, set a variable only once its new value is known to be valid. Task-number: QTBUG-111228 Change-Id: Ib6aa16e8c834f89c6ccc0715f20b0e5f0a7f3b6d Reviewed-by: Konrad Kujawa (cherry picked from commit 40b07ee887d9717088e3189b15c86a5c87759b1d) Reviewed-by: Qt Cherry-pick Bot --- examples/corelib/serialization/convert/xmlconverter.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/corelib/serialization/convert/xmlconverter.cpp b/examples/corelib/serialization/convert/xmlconverter.cpp index 080528f6785..9d08be2e553 100644 --- a/examples/corelib/serialization/convert/xmlconverter.cpp +++ b/examples/corelib/serialization/convert/xmlconverter.cpp @@ -180,23 +180,23 @@ static QVariant variantFromXml(QXmlStreamReader &xml, Converter::Options options text = text.trimmed(); QVariant result; - bool ok; if (type.isEmpty()) { // ok } else if (type == QLatin1String("number")) { // try integer first + bool ok; qint64 v = text.toLongLong(&ok); if (ok) { result = v; } else { // let's see floating point double d = text.toDouble(&ok); - result = d; if (!ok) { fprintf(stderr, "%lld:%lld: Invalid XML: could not interpret '%s' as a number.\n", xml.lineNumber(), xml.columnNumber(), qPrintable(text.toString())); exit(EXIT_FAILURE); } + result = d; } } else if (type == QLatin1String("bytes")) { QByteArray data = text.toLatin1();