mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-08 15:05:53 +00:00
ICU-8218 Fix symbol value check
X-SVN-Rev: 29683
This commit is contained in:
parent
74e7b59d02
commit
934d73b4ea
2 changed files with 33 additions and 3 deletions
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 1996-2010, International Business Machines
|
||||
* Copyright (C) 1996-2011, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*******************************************************************************
|
||||
* Modification History:
|
||||
|
@ -849,7 +849,7 @@ unum_getSymbol(const UNumberFormat *fmt,
|
|||
if(status==NULL || U_FAILURE(*status)) {
|
||||
return 0;
|
||||
}
|
||||
if(fmt==NULL || (uint16_t)symbol>=UNUM_FORMAT_SYMBOL_COUNT) {
|
||||
if(fmt==NULL || symbol< 0 || symbol>=UNUM_FORMAT_SYMBOL_COUNT) {
|
||||
*status=U_ILLEGAL_ARGUMENT_ERROR;
|
||||
return 0;
|
||||
}
|
||||
|
@ -876,7 +876,7 @@ unum_setSymbol(UNumberFormat *fmt,
|
|||
if(status==NULL || U_FAILURE(*status)) {
|
||||
return;
|
||||
}
|
||||
if(fmt==NULL || (uint16_t)symbol>=UNUM_FORMAT_SYMBOL_COUNT || value==NULL || length<-1) {
|
||||
if(fmt==NULL || symbol< 0 || symbol>=UNUM_FORMAT_SYMBOL_COUNT || value==NULL || length<-1) {
|
||||
*status=U_ILLEGAL_ARGUMENT_ERROR;
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -922,6 +922,36 @@ free(result);
|
|||
unum_close(fmt);
|
||||
}
|
||||
|
||||
status = U_ZERO_ERROR;
|
||||
/* Test invalid symbol argument */
|
||||
{
|
||||
int32_t badsymbolLarge = UNUM_FORMAT_SYMBOL_COUNT + 1;
|
||||
int32_t badsymbolSmall = -1;
|
||||
UChar value[10];
|
||||
int32_t valueLength = 10;
|
||||
UNumberFormat *fmt = unum_open(UNUM_DEFAULT, NULL, 0, NULL, NULL, &status);
|
||||
if (U_FAILURE(status)) {
|
||||
log_err("File %s, Line %d, status = %s\n", __FILE__, __LINE__, u_errorName(status));
|
||||
} else {
|
||||
unum_getSymbol(fmt, (UNumberFormatSymbol)badsymbolLarge, NULL, 0, &status);
|
||||
if (U_SUCCESS(status)) log_err("unum_getSymbol()'s status should be ILLEGAL_ARGUMENT with invalid symbol (> UNUM_FORMAT_SYMBOL_COUNT) argument\n");
|
||||
|
||||
status = U_ZERO_ERROR;
|
||||
unum_getSymbol(fmt, (UNumberFormatSymbol)badsymbolSmall, NULL, 0, &status);
|
||||
if (U_SUCCESS(status)) log_err("unum_getSymbol()'s status should be ILLEGAL_ARGUMENT with invalid symbol (less than 0) argument\n");
|
||||
|
||||
status = U_ZERO_ERROR;
|
||||
unum_setSymbol(fmt, (UNumberFormatSymbol)badsymbolLarge, value, valueLength, &status);
|
||||
if (U_SUCCESS(status)) log_err("unum_setSymbol()'s status should be ILLEGAL_ARGUMENT with invalid symbol (> UNUM_FORMAT_SYMBOL_COUNT) argument\n");
|
||||
|
||||
status = U_ZERO_ERROR;
|
||||
unum_setSymbol(fmt, (UNumberFormatSymbol)badsymbolSmall, value, valueLength, &status);
|
||||
if (U_SUCCESS(status)) log_err("unum_setSymbol()'s status should be ILLEGAL_ARGUMENT with invalid symbol (less than 0) argument\n");
|
||||
|
||||
unum_close(fmt);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*closing the NumberFormat() using unum_close(UNumberFormat*)")*/
|
||||
unum_close(def);
|
||||
|
|
Loading…
Add table
Reference in a new issue