From a989051519cbcb00af41aee6637259846a0d92f3 Mon Sep 17 00:00:00 2001
From: Konstantin Osipov <kostja.osipov@gmail.com>
Date: Thu, 26 May 2011 18:24:15 +0400
Subject: [PATCH] Bug#773058: review fixes.

Adjust signature of tbuf_ltrim, add comments,
replace a check with an assert.
---
 core/tbuf.c    | 15 +++++++--------
 include/tbuf.h | 11 ++++++++++-
 2 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/core/tbuf.c b/core/tbuf.c
index bb9fb13696..4e8e803ddc 100644
--- a/core/tbuf.c
+++ b/core/tbuf.c
@@ -124,17 +124,16 @@ tbuf_peek(struct tbuf *b, size_t count)
 	return NULL;
 }
 
-void *
+/** Remove first count bytes from the beginning. */
+
+void
 tbuf_ltrim(struct tbuf *b, size_t count)
 {
-	void *p = NULL;
-
 	tbuf_assert(b);
-	if (count <= b->len) {
-		p = memmove(b->data, b->data + count, b->len - count);
-		b->len -= count;
-	}
-	return p;
+	assert(count <= b->len);
+
+	memmove(b->data, b->data + count, b->len - count);
+	b->len -= count;
 }
 
 size_t
diff --git a/include/tbuf.h b/include/tbuf.h
index e45d44fc09..a504111a0f 100644
--- a/include/tbuf.h
+++ b/include/tbuf.h
@@ -63,7 +63,16 @@ struct tbuf *tbuf_split(struct tbuf *e, size_t at);
 size_t tbuf_reserve(struct tbuf *b, size_t count);
 void tbuf_reset(struct tbuf *b);
 void *tbuf_peek(struct tbuf *b, size_t count);
-void *tbuf_ltrim(struct tbuf *b, size_t count);
+
+/**
+ * Remove count bytes from the beginning, and adjust all sizes
+ * accordingly.
+ *
+ * @param    count   the number of bytes to forget about.
+ *
+ * @pre      0 <= count <= tbuf->len
+ */
+void tbuf_ltrim(struct tbuf *b, size_t count);
 
 void tbuf_append_field(struct tbuf *b, void *f);
 void tbuf_vprintf(struct tbuf *b, const char *format, va_list ap)
-- 
GitLab