From a9b1fbdcc5aba16cb5b5d3acdbbe2b4e48768e1c Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Sun, 27 Oct 2019 14:24:10 -0400 Subject: Don't expose 'detach_buffer()' to membuffer users The native buffer of a membuffer is not NUL-terminated, so when you want to detach it and use it as a C string, you had to first do 'mb_cstring()' that adds the proper termination/ This was all documented in the header files, and all but two users did it correctly. But there were those two users, and the exported interface was unnecessarily hard to use. We do want the "just detach the raw buffer" internally in the membuffer code, but let's not make the exported interface be that hard to use. So this switches the exported interface to be 'detach_cstring()', which does that 'mb_cstring()' for you, and avoids the possibility that you'd use a non-terminated memory buffer as a C string. The old 'detach_buffer()' is now purely the internal membuffer implementation, and not used by others. Signed-off-by: Linus Torvalds --- desktop-widgets/tab-widgets/TabDivePhotos.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'desktop-widgets') diff --git a/desktop-widgets/tab-widgets/TabDivePhotos.cpp b/desktop-widgets/tab-widgets/TabDivePhotos.cpp index 72a14916b..775308e3b 100644 --- a/desktop-widgets/tab-widgets/TabDivePhotos.cpp +++ b/desktop-widgets/tab-widgets/TabDivePhotos.cpp @@ -132,7 +132,7 @@ void TabDivePhotos::saveSubtitles() continue; struct membuffer b = { 0 }; save_subtitles_buffer(&b, &displayed_dive, offset, duration); - char *data = detach_buffer(&b); + char *data = detach_cstring(&b); subtitlefile.open(QIODevice::WriteOnly); subtitlefile.write(data, strlen(data)); subtitlefile.close(); -- cgit v1.2.3-70-g09d2