diff options
author | 2021-07-20 07:24:07 +0200 | |
---|---|---|
committer | 2021-07-23 11:22:43 -0700 | |
commit | f142e9a9c6ba493c09a282544da8715b3656648e (patch) | |
tree | 8b419cad550f086022acdc175a7cc7dd65e7f1e2 /core/format.cpp | |
parent | 0c84f369c35bf416071b9ef6d5a401b457fd4a38 (diff) | |
download | subsurface-f142e9a9c6ba493c09a282544da8715b3656648e.tar.gz |
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 <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/format.cpp')
-rw-r--r-- | core/format.cpp | 2 |
1 files changed, 0 insertions, 2 deletions
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; } - |