From 8d11577ff2b7caf846a31cbb57b2cf9eb3515961 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 25 Jun 2015 22:43:55 +0200 Subject: lib/icu/{Converter,Collate}: return AllocatedString --- src/lib/icu/Util.cxx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/lib/icu/Util.cxx') diff --git a/src/lib/icu/Util.cxx b/src/lib/icu/Util.cxx index ae47423ad..92f1de5aa 100644 --- a/src/lib/icu/Util.cxx +++ b/src/lib/icu/Util.cxx @@ -19,6 +19,7 @@ #include "config.h" #include "Util.hxx" +#include "util/AllocatedString.hxx" #include "util/WritableBuffer.hxx" #include "util/ConstBuffer.hxx" @@ -49,7 +50,7 @@ UCharFromUTF8(const char *src) return { dest, size_t(dest_length) }; } -WritableBuffer +AllocatedString<> UCharToUTF8(ConstBuffer src) { assert(!src.IsNull()); @@ -57,7 +58,7 @@ UCharToUTF8(ConstBuffer src) /* worst-case estimate */ size_t dest_capacity = 4 * src.size; - char *dest = new char[dest_capacity]; + char *dest = new char[dest_capacity + 1]; UErrorCode error_code = U_ZERO_ERROR; int32_t dest_length; @@ -68,5 +69,6 @@ UCharToUTF8(ConstBuffer src) return nullptr; } - return { dest, size_t(dest_length) }; + dest[dest_length] = 0; + return AllocatedString<>::Donate(dest); } -- cgit v1.2.3