From 9dd987561120246cd8169cfdbd00e8164542ec01 Mon Sep 17 00:00:00 2001
From: Jason Volk <jason@zemos.net>
Date: Tue, 23 Jun 2020 00:53:56 -0700
Subject: [PATCH] ircd::spirit: Assertions for output buffer state in generate
 template.

---
 include/ircd/spirit.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/include/ircd/spirit.h b/include/ircd/spirit.h
index ebb350710..f61bba943 100644
--- a/include/ircd/spirit.h
+++ b/include/ircd/spirit.h
@@ -319,7 +319,8 @@ ircd::spirit::generate(mutable_buffer &out,
 
 	if constexpr(truncation)
 	{
-		begin(out) = state.overflow? end(out) : begin(out);
+		assert(begin(out) <= end(out));
+		begin(out) = state.overflow? end(out): begin(out);
 		assert(!state.overflow || begin(out) == end(out));
 		assert(begin(out) <= end(out));
 		return ret;
@@ -334,6 +335,7 @@ ircd::spirit::generate(mutable_buffer &out,
 				std::distance(start, begin(out))
 		};
 
+		assert(begin(out) <= end(out));
 		throw buffer_overrun
 		{
 			"Insufficient buffer of %s; required at least %s",