From f142e9a9c6ba493c09a282544da8715b3656648e Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Tue, 20 Jul 2021 07:24:07 +0200 Subject: core: C++-ify membuffer C-style memory management is a pain and nearly nobody seems to get it right. Add a C++-version of membuffer that frees the buffer when it gets out-of-scope. Originally, I was thinking about conditionally adding a constructor/destructor pair when compiling with C++. But then decided to create a derived class membufferpp, because it would be extremely confusing to have behavioral change when changing a source from from C to C++ or vice-versa. Also add a comment about the dangers of returned pointer: They become dangling on changes to the membuffer. Signed-off-by: Berthold Stoeger --- core/format.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'core/format.cpp') diff --git a/core/format.cpp b/core/format.cpp index a540f4c21..3da97293a 100644 --- a/core/format.cpp +++ b/core/format.cpp @@ -397,7 +397,6 @@ int vasprintf_loc(char **dst, const char *cformat, va_list ap) return utf8.size(); } -// This function is defined here instead of membuffer.c, because it needs to access QString. extern "C" void put_vformat_loc(struct membuffer *b, const char *fmt, va_list args) { QByteArray utf8 = vqasprintf_loc(fmt, args).toUtf8(); @@ -408,4 +407,3 @@ extern "C" void put_vformat_loc(struct membuffer *b, const char *fmt, va_list ar memcpy(b->buffer + b->len, data, utf8_size); b->len += utf8_size; } - -- cgit v1.2.3-70-g09d2