From 8e74b5cfe43893522c0f06d0b0d0dd5b7393aa6f Mon Sep 17 00:00:00 2001 From: Konstantin Ritt Date: Tue, 10 Apr 2012 14:53:42 +0300 Subject: [PATCH] fix digitValue() returned 0 instead of -1 for invalid ucs4 characters Task-number: QTBUG-20318 Change-Id: I96c4c2b042bad478b7c704669e7ea0d574d3b22f Reviewed-by: Robin Burchell Reviewed-by: Oswald Buddenhagen Reviewed-by: Lars Knoll --- src/corelib/tools/qchar.cpp | 2 +- tests/auto/corelib/tools/qchar/tst_qchar.cpp | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/corelib/tools/qchar.cpp b/src/corelib/tools/qchar.cpp index 6efd9f2..1ce19ec 100644 --- a/src/corelib/tools/qchar.cpp +++ b/src/corelib/tools/qchar.cpp @@ -717,7 +717,7 @@ int QChar::digitValue(ushort ucs2) int QChar::digitValue(uint ucs4) { if (ucs4 > UNICODE_LAST_CODEPOINT) - return 0; + return -1; return qGetProp(ucs4)->digitValue; } diff --git a/tests/auto/corelib/tools/qchar/tst_qchar.cpp b/tests/auto/corelib/tools/qchar/tst_qchar.cpp index e72af11..215f4c1 100644 --- a/tests/auto/corelib/tools/qchar/tst_qchar.cpp +++ b/tests/auto/corelib/tools/qchar/tst_qchar.cpp @@ -523,6 +523,9 @@ void tst_QChar::digitValue() QVERIFY(QChar::digitValue((ushort)0x1040) == 0); QVERIFY(QChar::digitValue((uint)0x1049) == 9); QVERIFY(QChar::digitValue((uint)0x1040) == 0); + + QVERIFY(QChar::digitValue((ushort)0xd800) == -1); + QVERIFY(QChar::digitValue((uint)UNICODE_LAST_CODEPOINT + 1) == -1); } void tst_QChar::decomposition() -- 2.7.4