From 3b9134422d75ab11ac39184ef01e7616fbfcc1aa Mon Sep 17 00:00:00 2001 From: /dev/urandom Date: Mon, 29 Aug 2016 10:11:03 +0200 Subject: [PATCH] Fix Base128 utility function. --- src/Utils/String.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Utils/String.cpp b/src/Utils/String.cpp index a9ab39d1..368a5e14 100644 --- a/src/Utils/String.cpp +++ b/src/Utils/String.cpp @@ -137,8 +137,14 @@ namespace Utils auto encoder = new base128(); void* inbuffer = const_cast(input.data()); char* buffer = encoder->encode(inbuffer, input.size()); + /* + Interesting to see that the buffer returned by the encoder is not a standalone string copy + but instead is a pointer to the internal "encoded" field of the encoder. So if you deinitialize + the encoder that string will probably become garbage. + */ + std::string retval(buffer); delete encoder; - return std::string(buffer); + return retval; } // Generates a UUID and returns the string representation of it