Repository: lucy-clownfish Updated Branches: refs/heads/master 658d11806 -> bd503cb73
Null-terminate buffer in CB_Yield_String This makes sure that strings created with CharBufs can safely be accessed as C strings. Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/e5b853eb Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/e5b853eb Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/e5b853eb Branch: refs/heads/master Commit: e5b853ebef110918526d6bd961d06a83d4230109 Parents: 658d118 Author: Nick Wellnhofer <wellnho...@aevum.de> Authored: Wed Apr 6 16:25:23 2016 +0200 Committer: Nick Wellnhofer <wellnho...@aevum.de> Committed: Wed Apr 6 16:25:23 2016 +0200 ---------------------------------------------------------------------- runtime/core/Clownfish/CharBuf.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/e5b853eb/runtime/core/Clownfish/CharBuf.c ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/CharBuf.c b/runtime/core/Clownfish/CharBuf.c index 3867249..e6392b2 100644 --- a/runtime/core/Clownfish/CharBuf.c +++ b/runtime/core/Clownfish/CharBuf.c @@ -273,11 +273,18 @@ CB_To_String_IMP(CharBuf *self) { String* CB_Yield_String_IMP(CharBuf *self) { - String *retval - = Str_new_steal_trusted_utf8(self->ptr, self->size); + // Null-terminate buffer. + size_t size = self->size; + SI_add_grow_and_oversize(self, size, 1); + self->ptr[size] = '\0'; + + String *retval = Str_new_steal_trusted_utf8(self->ptr, size); + + // Clear CharBuf. self->ptr = NULL; self->size = 0; self->cap = 0; + return retval; }