Fix error handling in GetLocaleIso639LanguageTwoLetterName
authorFilip Navara <filip.navara@gmail.com>
Sun, 3 Feb 2019 02:20:45 +0000 (03:20 +0100)
committerFilip Navara <filip.navara@gmail.com>
Sun, 3 Feb 2019 10:18:02 +0000 (11:18 +0100)
Commit migrated from https://github.com/dotnet/coreclr/commit/1edbceb16f7f54c535d4a8416cf2c34691e484bc

src/coreclr/src/corefx/System.Globalization.Native/pal_localeStringData.c

index d17e667..f8c9e87 100644 (file)
@@ -72,12 +72,14 @@ UErrorCode GetLocaleIso639LanguageTwoLetterName(const char* locale, UChar* value
     UErrorCode status = U_ZERO_ERROR;
     int32_t length = uloc_getLanguage(locale, NULL, 0, &status) + 1;
 
+    assert(status == U_BUFFER_OVERFLOW_ERROR);
     char* buf = calloc(length, sizeof(char));
     if (buf == NULL)
     {
         return U_MEMORY_ALLOCATION_ERROR;
     }
 
+    status = U_ZERO_ERROR;
     uloc_getLanguage(locale, buf, length, &status);
 
     if (U_SUCCESS(status))