ICU-13210 remove unreachable code, improve pattern pointer check

X-SVN-Rev: 40491
This commit is contained in:
Markus Scherer 2017-09-27 23:28:43 +00:00
parent 0d9ef38e4c
commit 45a6728cbe
2 changed files with 6 additions and 7 deletions

View File

@ -321,7 +321,7 @@ umsg_applyPattern(UMessageFormat *fmt,
if(status ==NULL||U_FAILURE(*status)){ if(status ==NULL||U_FAILURE(*status)){
return ; return ;
} }
if(fmt==NULL||pattern==NULL||patternLength<-1){ if(fmt==NULL || (pattern==NULL && patternLength!=0) || patternLength<-1) {
*status=U_ILLEGAL_ARGUMENT_ERROR; *status=U_ILLEGAL_ARGUMENT_ERROR;
return ; return ;
} }
@ -329,10 +329,8 @@ umsg_applyPattern(UMessageFormat *fmt,
if(parseError==NULL){ if(parseError==NULL){
parseError = &tErr; parseError = &tErr;
} }
if(patternLength<-1){
patternLength=u_strlen(pattern);
}
// UnicodeString(pattern, -1) calls u_strlen().
((MessageFormat*)fmt)->applyPattern(UnicodeString(pattern,patternLength),*parseError,*status); ((MessageFormat*)fmt)->applyPattern(UnicodeString(pattern,patternLength),*parseError,*status);
} }

View File

@ -188,7 +188,7 @@ static void MessageFormatTest( void )
UMessageFormat formatter = umsg_open(testCasePatterns[0],patternLength,"en_US",NULL,&ec); UMessageFormat formatter = umsg_open(testCasePatterns[0],patternLength,"en_US",NULL,&ec);
if(U_FAILURE(ec)){ if(U_FAILURE(ec)){
log_data_err("umsg_open() failed for testCasePattens[%d]. -> %s (Are you missing data?)\n",i, u_errorName(ec)); log_data_err("umsg_open() failed for testCasePattens[0]. -> %s (Are you missing data?)\n", u_errorName(ec));
return; return;
} }
for(i = 0;i<cnt_testCases; i++){ for(i = 0;i<cnt_testCases; i++){
@ -199,8 +199,9 @@ static void MessageFormatTest( void )
UDate d2=0; UDate d2=0;
result=NULL; result=NULL;
patternLength = u_strlen(testCasePatterns[i]); // Alternate between specifying the length and using NUL-termination.
patternLength = ((i & 1) == 0) ? u_strlen(testCasePatterns[i]) : -1;
umsg_applyPattern(formatter,testCasePatterns[i],patternLength,&parseError,&ec); umsg_applyPattern(formatter,testCasePatterns[i],patternLength,&parseError,&ec);
if(U_FAILURE(ec)){ if(U_FAILURE(ec)){
log_err("umsg_applyPattern() failed for testCasePattens[%d].\n",i); log_err("umsg_applyPattern() failed for testCasePattens[%d].\n",i);