]> granicus.if.org Git - icu/commitdiff
ICU-13210 remove unreachable code, improve pattern pointer check
authorMarkus Scherer <markus.icu@gmail.com>
Wed, 27 Sep 2017 23:28:43 +0000 (23:28 +0000)
committerMarkus Scherer <markus.icu@gmail.com>
Wed, 27 Sep 2017 23:28:43 +0000 (23:28 +0000)
X-SVN-Rev: 40491

icu4c/source/i18n/umsg.cpp
icu4c/source/test/cintltst/cmsgtst.c

index 623e06976c6d38372115f4c364f81cce598ef6ae..31eeacbef1f56d84fb9474734fbe11f8e6bba4b2 100644 (file)
@@ -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);  
 }
 
index 21b6e5a6e63aa615ab04a0c1d11975b0c7f44b8c..8ed4969d6ccf8f079c80f0e9a47863bfa068c294 100644 (file)
@@ -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<cnt_testCases; i++){
@@ -199,8 +199,9 @@ static void MessageFormatTest( void )
             UDate d2=0;
     
             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);
             if(U_FAILURE(ec)){
                 log_err("umsg_applyPattern() failed for testCasePattens[%d].\n",i);