@@ -2468,7 +2468,7 @@ pg_ucol_open(const char *loc_str)
2468
2468
2469
2469
status = U_ZERO_ERROR ;
2470
2470
uloc_getLanguage (loc_str , lang , ULOC_LANG_CAPACITY , & status );
2471
- if (U_FAILURE (status ))
2471
+ if (U_FAILURE (status ) || status == U_STRING_NOT_TERMINATED_WARNING )
2472
2472
{
2473
2473
ereport (ERROR ,
2474
2474
(errmsg ("could not get language from locale \"%s\": %s" ,
@@ -2504,7 +2504,7 @@ pg_ucol_open(const char *loc_str)
2504
2504
* Pretend the error came from ucol_open(), for consistent error
2505
2505
* message across ICU versions.
2506
2506
*/
2507
- if (U_FAILURE (status ))
2507
+ if (U_FAILURE (status ) || status == U_STRING_NOT_TERMINATED_WARNING )
2508
2508
{
2509
2509
ucol_close (collator );
2510
2510
ereport (ERROR ,
@@ -2639,7 +2639,8 @@ icu_from_uchar(char **result, const UChar *buff_uchar, int32_t len_uchar)
2639
2639
status = U_ZERO_ERROR ;
2640
2640
len_result = ucnv_fromUChars (icu_converter , * result , len_result + 1 ,
2641
2641
buff_uchar , len_uchar , & status );
2642
- if (U_FAILURE (status ))
2642
+ if (U_FAILURE (status ) ||
2643
+ status == U_STRING_NOT_TERMINATED_WARNING )
2643
2644
ereport (ERROR ,
2644
2645
(errmsg ("%s failed: %s" , "ucnv_fromUChars" ,
2645
2646
u_errorName (status ))));
@@ -2681,7 +2682,7 @@ icu_set_collation_attributes(UCollator *collator, const char *loc,
2681
2682
icu_locale_id = palloc (len + 1 );
2682
2683
* status = U_ZERO_ERROR ;
2683
2684
len = uloc_canonicalize (loc , icu_locale_id , len + 1 , status );
2684
- if (U_FAILURE (* status ))
2685
+ if (U_FAILURE (* status ) || * status == U_STRING_NOT_TERMINATED_WARNING )
2685
2686
return ;
2686
2687
2687
2688
lower_str = asc_tolower (icu_locale_id , strlen (icu_locale_id ));
@@ -2765,7 +2766,6 @@ icu_set_collation_attributes(UCollator *collator, const char *loc,
2765
2766
2766
2767
pfree (lower_str );
2767
2768
}
2768
-
2769
2769
#endif
2770
2770
2771
2771
/*
@@ -2789,7 +2789,7 @@ icu_language_tag(const char *loc_str, int elevel)
2789
2789
2790
2790
status = U_ZERO_ERROR ;
2791
2791
uloc_getLanguage (loc_str , lang , ULOC_LANG_CAPACITY , & status );
2792
- if (U_FAILURE (status ))
2792
+ if (U_FAILURE (status ) || status == U_STRING_NOT_TERMINATED_WARNING )
2793
2793
{
2794
2794
if (elevel > 0 )
2795
2795
ereport (elevel ,
@@ -2811,19 +2811,12 @@ icu_language_tag(const char *loc_str, int elevel)
2811
2811
langtag = palloc (buflen );
2812
2812
while (true)
2813
2813
{
2814
- int32_t len ;
2815
-
2816
2814
status = U_ZERO_ERROR ;
2817
- len = uloc_toLanguageTag (loc_str , langtag , buflen , strict , & status );
2815
+ uloc_toLanguageTag (loc_str , langtag , buflen , strict , & status );
2818
2816
2819
- /*
2820
- * If the result fits in the buffer exactly (len == buflen),
2821
- * uloc_toLanguageTag() will return success without nul-terminating
2822
- * the result. Check for either U_BUFFER_OVERFLOW_ERROR or len >=
2823
- * buflen and try again.
2824
- */
2817
+ /* try again if the buffer is not large enough */
2825
2818
if ((status == U_BUFFER_OVERFLOW_ERROR ||
2826
- ( U_SUCCESS ( status ) && len >= buflen ) ) &&
2819
+ status == U_STRING_NOT_TERMINATED_WARNING ) &&
2827
2820
buflen < MaxAllocSize )
2828
2821
{
2829
2822
buflen = Min (buflen * 2 , MaxAllocSize );
@@ -2878,7 +2871,7 @@ icu_validate_locale(const char *loc_str)
2878
2871
/* validate that we can extract the language */
2879
2872
status = U_ZERO_ERROR ;
2880
2873
uloc_getLanguage (loc_str , lang , ULOC_LANG_CAPACITY , & status );
2881
- if (U_FAILURE (status ))
2874
+ if (U_FAILURE (status ) || status == U_STRING_NOT_TERMINATED_WARNING )
2882
2875
{
2883
2876
ereport (elevel ,
2884
2877
(errmsg ("could not get language from ICU locale \"%s\": %s" ,
@@ -2901,7 +2894,7 @@ icu_validate_locale(const char *loc_str)
2901
2894
2902
2895
status = U_ZERO_ERROR ;
2903
2896
uloc_getLanguage (otherloc , otherlang , ULOC_LANG_CAPACITY , & status );
2904
- if (U_FAILURE (status ))
2897
+ if (U_FAILURE (status ) || status == U_STRING_NOT_TERMINATED_WARNING )
2905
2898
continue ;
2906
2899
2907
2900
if (strcmp (lang , otherlang ) == 0 )
0 commit comments