From 26e874722bebb95e27b9ce2fba14812b885aaf19 Mon Sep 17 00:00:00 2001 From: Matt Ellis Date: Thu, 22 Oct 2015 17:46:54 -0700 Subject: 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. --- .../System.Globalization.Native/calendarData.cpp | 24 ++++++---------------- 1 file changed, 6 insertions(+), 18 deletions(-) (limited to 'src/corefx') 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 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 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); } -- cgit v1.2.3