From 45a6728cbe4c29bc77d833254c1ac73d55c987d3 Mon Sep 17 00:00:00 2001 From: Markus Scherer Date: Wed, 27 Sep 2017 23:28:43 +0000 Subject: [PATCH] ICU-13210 remove unreachable code, improve pattern pointer check X-SVN-Rev: 40491 --- icu4c/source/i18n/umsg.cpp | 6 ++---- icu4c/source/test/cintltst/cmsgtst.c | 7 ++++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/icu4c/source/i18n/umsg.cpp b/icu4c/source/i18n/umsg.cpp index 623e06976c6..31eeacbef1f 100644 --- a/icu4c/source/i18n/umsg.cpp +++ b/icu4c/source/i18n/umsg.cpp @@ -321,7 +321,7 @@ umsg_applyPattern(UMessageFormat *fmt, if(status ==NULL||U_FAILURE(*status)){ return ; } - if(fmt==NULL||pattern==NULL||patternLength<-1){ + if(fmt==NULL || (pattern==NULL && patternLength!=0) || patternLength<-1) { *status=U_ILLEGAL_ARGUMENT_ERROR; return ; } @@ -329,10 +329,8 @@ umsg_applyPattern(UMessageFormat *fmt, if(parseError==NULL){ parseError = &tErr; } - if(patternLength<-1){ - patternLength=u_strlen(pattern); - } + // UnicodeString(pattern, -1) calls u_strlen(). ((MessageFormat*)fmt)->applyPattern(UnicodeString(pattern,patternLength),*parseError,*status); } diff --git a/icu4c/source/test/cintltst/cmsgtst.c b/icu4c/source/test/cintltst/cmsgtst.c index 21b6e5a6e63..8ed4969d6cc 100644 --- a/icu4c/source/test/cintltst/cmsgtst.c +++ b/icu4c/source/test/cintltst/cmsgtst.c @@ -188,7 +188,7 @@ static void MessageFormatTest( void ) UMessageFormat formatter = umsg_open(testCasePatterns[0],patternLength,"en_US",NULL,&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; } for(i = 0;i