mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
d401271dab
commit
a9b1fbdcc5
7 changed files with 20 additions and 22 deletions
|
|
@ -12,7 +12,8 @@
|
|||
#include "dive.h"
|
||||
#include "membuffer.h"
|
||||
|
||||
char *detach_buffer(struct membuffer *b)
|
||||
/* Only for internal use */
|
||||
static char *detach_buffer(struct membuffer *b)
|
||||
{
|
||||
char *result = b->buffer;
|
||||
b->buffer = NULL;
|
||||
|
|
@ -21,6 +22,12 @@ char *detach_buffer(struct membuffer *b)
|
|||
return result;
|
||||
}
|
||||
|
||||
char *detach_cstring(struct membuffer *b)
|
||||
{
|
||||
mb_cstring(b);
|
||||
return detach_buffer(b);
|
||||
}
|
||||
|
||||
void free_buffer(struct membuffer *b)
|
||||
{
|
||||
free(detach_buffer(b));
|
||||
|
|
@ -117,8 +124,7 @@ char *vformat_string(const char *fmt, va_list args)
|
|||
{
|
||||
struct membuffer mb = { 0 };
|
||||
put_vformat(&mb, fmt, args);
|
||||
mb_cstring(&mb);
|
||||
return detach_buffer(&mb);
|
||||
return detach_cstring(&mb);
|
||||
}
|
||||
|
||||
char *format_string(const char *fmt, ...)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue