From 275982d1315d93c0396f26d69c50b80de6e922f1 Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Mon, 26 Nov 2018 15:39:11 +0000 Subject: [PATCH] add Buffer fixup functions This is split out of another upstream commit --- mutt/buffer.c | 20 ++++++++++++++++++++ mutt/buffer.h | 1 + 2 files changed, 21 insertions(+) diff --git a/mutt/buffer.c b/mutt/buffer.c index 230d6161f..3278c4868 100644 --- a/mutt/buffer.c +++ b/mutt/buffer.c @@ -209,6 +209,26 @@ int mutt_buffer_printf(struct Buffer *buf, const char *fmt, ...) return len; } +/** + * mutt_buffer_fix_dptr - Move the dptr to end of the Buffer + * @param buf Buffer to alter + * + * Ensure buffer->dptr points to the end of the buffer. + */ +void mutt_buffer_fix_dptr(struct Buffer *buf) +{ + if (!buf) + return; + + buf->dptr = buf->data; + + if (buf->data) + { + buf->data[buf->dsize - 1] = '\0'; + buf->dptr = strchr(buf->data, '\0'); + } +} + /** * mutt_buffer_add_printf - Format a string appending a Buffer * @param buf Buffer diff --git a/mutt/buffer.h b/mutt/buffer.h index 5bd2a4d2a..83dc0d440 100644 --- a/mutt/buffer.h +++ b/mutt/buffer.h @@ -48,6 +48,7 @@ size_t mutt_buffer_addch (struct Buffer *buf, char c); size_t mutt_buffer_addstr (struct Buffer *buf, const char *s); int mutt_buffer_add_printf (struct Buffer *buf, const char *fmt, ...); struct Buffer *mutt_buffer_alloc (size_t size); +void mutt_buffer_fix_dptr (struct Buffer *buf); void mutt_buffer_free (struct Buffer **p); struct Buffer *mutt_buffer_from (const char *seed); void mutt_buffer_increase_size(struct Buffer *buf, size_t new_size); -- 2.40.0