diff options
author | Matt Ellis <matell@microsoft.com> | 2015-10-22 17:46:54 -0700 |
---|---|---|
committer | Matt Ellis <matell@microsoft.com> | 2015-10-22 17:46:54 -0700 |
commit | 26e874722bebb95e27b9ce2fba14812b885aaf19 (patch) | |
tree | 971ea35f3657db87b315252c074507078386372f /src/corefx | |
parent | f17e90cb25573fbc7894725ccd008a2fb116236f (diff) | |
download | coreclr-26e874722bebb95e27b9ce2fba14812b885aaf19.tar.gz coreclr-26e874722bebb95e27b9ce2fba14812b885aaf19.tar.bz2 coreclr-26e874722bebb95e27b9ce2fba14812b885aaf19.zip |
Use std::vector instead of calloc
This matches what we do in other places in calendarData.cpp, the RAII
pattern will make it easier to not leak memory.
Diffstat (limited to 'src/corefx')
-rw-r--r-- | src/corefx/System.Globalization.Native/calendarData.cpp | 24 |
1 files changed, 6 insertions, 18 deletions
diff --git a/src/corefx/System.Globalization.Native/calendarData.cpp b/src/corefx/System.Globalization.Native/calendarData.cpp index 54fd471d71..6e971d89ef 100644 --- a/src/corefx/System.Globalization.Native/calendarData.cpp +++ b/src/corefx/System.Globalization.Native/calendarData.cpp @@ -329,20 +329,15 @@ bool InvokeCallbackForDatePattern(const char* locale, UErrorCode ignore = U_ZERO_ERROR; int32_t patternLen = udat_toPattern(pFormat, false, nullptr, 0, &ignore); - UChar* pattern = (UChar*)calloc(patternLen + 1, sizeof(UChar)); + std::vector<UChar> pattern(patternLen + 1, '\0'); - if (pattern == nullptr) - return false; - - udat_toPattern(pFormat, false, pattern, patternLen + 1, &err); + udat_toPattern(pFormat, false, pattern.data(), patternLen + 1, &err); if (U_SUCCESS(err)) { - callback(pattern, context); + callback(pattern.data(), context); } - free(pattern); - return U_SUCCESS(err); } @@ -368,22 +363,15 @@ bool InvokeCallbackForDateTimePattern(const char* locale, UErrorCode ignore = U_ZERO_ERROR; int32_t patternLen = udatpg_getBestPattern(pGenerator, patternSkeleton, -1, nullptr, 0, &ignore); - UChar* bestPattern = (UChar*)calloc(patternLen + 1, sizeof(UChar)); - - if (bestPattern == nullptr) - { - return false; - } + std::vector<UChar> bestPattern(patternLen + 1, '\0'); - udatpg_getBestPattern(pGenerator, patternSkeleton, -1, bestPattern, patternLen + 1, &err); + udatpg_getBestPattern(pGenerator, patternSkeleton, -1, bestPattern.data(), patternLen + 1, &err); if (U_SUCCESS(err)) { - callback(bestPattern, context); + callback(bestPattern.data(), context); } - free(bestPattern); - return U_SUCCESS(err); } |