From f670636245fb407277e38224058616833994ae3e Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Fri, 26 Sep 2014 09:32:29 +0100 Subject: coverity#1241372 Negative array index read Change-Id: I73bae29c6cc737d341381c010face6b587b31598 --- .../source/nativenumber/nativenumbersupplier.cxx | 52 +++++++++++++--------- 1 file changed, 31 insertions(+), 21 deletions(-) (limited to 'i18npool/source') diff --git a/i18npool/source/nativenumber/nativenumbersupplier.cxx b/i18npool/source/nativenumber/nativenumbersupplier.cxx index a8f08badbab4..5c421f9bb72e 100644 --- a/i18npool/source/nativenumber/nativenumbersupplier.cxx +++ b/i18npool/source/nativenumber/nativenumbersupplier.cxx @@ -611,28 +611,38 @@ sal_Unicode SAL_CALL NativeNumberSupplierService::getNativeNumberChar( const sal return j; return inChar; } - else if (isNumber(inChar) && isValidNatNum(rLocale, nNativeNumberMode)) { - sal_Int16 langnum = getLanguageNumber(rLocale); - switch (nNativeNumberMode) { - case NativeNumberMode::NATNUM1: // Char, Lower - case NativeNumberMode::NATNUM4: // Text, Lower, Long - case NativeNumberMode::NATNUM7: // Text. Lower, Short - return NumberChar[natnum1[langnum]][inChar - NUMBER_ZERO]; - case NativeNumberMode::NATNUM2: // Char, Upper - case NativeNumberMode::NATNUM5: // Text, Upper, Long - case NativeNumberMode::NATNUM8: // Text, Upper, Short - return NumberChar[natnum2[langnum]][inChar - NUMBER_ZERO]; - case NativeNumberMode::NATNUM3: // Char, FullWidth - case NativeNumberMode::NATNUM6: // Text, FullWidth - return NumberChar[NumberChar_FullWidth][inChar - NUMBER_ZERO]; - case NativeNumberMode::NATNUM9: // Char, Hangul - case NativeNumberMode::NATNUM10: // Text, Hangul, Long - case NativeNumberMode::NATNUM11: // Text, Hangul, Short - return NumberChar[NumberChar_Hangul_ko][inChar - NUMBER_ZERO]; - default: - break; - } + + if (!isNumber(inChar)) + return inChar; + + if (!isValidNatNum(rLocale, nNativeNumberMode)) + return inChar; + + sal_Int16 langnum = getLanguageNumber(rLocale); + if (langnum == -1) + return inChar; + + switch (nNativeNumberMode) + { + case NativeNumberMode::NATNUM1: // Char, Lower + case NativeNumberMode::NATNUM4: // Text, Lower, Long + case NativeNumberMode::NATNUM7: // Text. Lower, Short + return NumberChar[natnum1[langnum]][inChar - NUMBER_ZERO]; + case NativeNumberMode::NATNUM2: // Char, Upper + case NativeNumberMode::NATNUM5: // Text, Upper, Long + case NativeNumberMode::NATNUM8: // Text, Upper, Short + return NumberChar[natnum2[langnum]][inChar - NUMBER_ZERO]; + case NativeNumberMode::NATNUM3: // Char, FullWidth + case NativeNumberMode::NATNUM6: // Text, FullWidth + return NumberChar[NumberChar_FullWidth][inChar - NUMBER_ZERO]; + case NativeNumberMode::NATNUM9: // Char, Hangul + case NativeNumberMode::NATNUM10: // Text, Hangul, Long + case NativeNumberMode::NATNUM11: // Text, Hangul, Short + return NumberChar[NumberChar_Hangul_ko][inChar - NUMBER_ZERO]; + default: + break; } + return inChar; } -- cgit