summaryrefslogtreecommitdiffstats
path: root/core/plannernotes.c
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2019-10-27 14:24:10 -0400
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-10-27 12:42:54 -0700
commita9b1fbdcc5aba16cb5b5d3acdbbe2b4e48768e1c (patch)
treefd8a32ac646d356c363b0cdc0390e6e7a48441eb /core/plannernotes.c
parentd401271dab8d114c74d7d9ceb1ac39290b1a80d8 (diff)
downloadsubsurface-a9b1fbdcc5aba16cb5b5d3acdbbe2b4e48768e1c.tar.gz
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 <torvalds@linux-foundation.org>
Diffstat (limited to 'core/plannernotes.c')
-rw-r--r--core/plannernotes.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/core/plannernotes.c b/core/plannernotes.c
index 2d7b77948..c72ac901a 100644
--- a/core/plannernotes.c
+++ b/core/plannernotes.c
@@ -89,7 +89,7 @@ char *get_planner_disclaimer_formatted()
const char *deco = decoMode() == VPMB ? translate("gettextFromC", "VPM-B")
: translate("gettextFromC", "BUHLMANN");
put_format(&buf, get_planner_disclaimer(), deco);
- return detach_buffer(&buf);
+ return detach_cstring(&buf);
}
void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool show_disclaimer, int error)
@@ -618,9 +618,8 @@ void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool show_d
if (o2warning_exist)
put_string(&buf, "</div>\n");
finished:
- mb_cstring(&buf);
free(dive->notes);
- dive->notes = detach_buffer(&buf);
+ dive->notes = detach_cstring(&buf);
#ifdef DEBUG_PLANNER_NOTES
printf("<!DOCTYPE html>\n<html>\n\t<head><title>plannernotes</title><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/></head>\n\t<body>\n%s\t</body>\n</html>\n", dive->notes);
#endif