From 268d4265ca278ec4f418b473b5024f910bc3ce99 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Fri, 5 Jun 2020 09:10:58 -0700 Subject: [PATCH] ircd::spirit: Improve generator overflow counting. --- include/ircd/spirit.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/include/ircd/spirit.h b/include/ircd/spirit.h index 351efb26a..e08d71713 100644 --- a/include/ircd/spirit.h +++ b/include/ircd/spirit.h @@ -260,6 +260,9 @@ struct ircd::spirit::generator_state /// Internal state for buffer_sink::copy() ssize_t last_generated {0}, last_width {0}; + + /// Count of rejected from the destination buffer. + ssize_t overflow {0}; }; template(g), std::forward(a)...) }; - if(unlikely(size_t(state.generated) > max)) + if(unlikely(state.overflow)) { char pbuf[2][48]; + begin(out) = end(out) - max; throw spirit::buffer_overrun { "Insufficient buffer of %s for %s", pretty(pbuf[0], iec(max)), - pretty(pbuf[1], iec(state.generated)), + pretty(pbuf[1], iec(max + state.overflow)), }; } + assert(begin(out) >= end(out) - max); + assert(begin(out) <= end(out)); return ret; } @@ -397,6 +403,7 @@ boost::spirit::karma::detail::buffer_sink::output(const char &value) }; this->width += consumed; + state.overflow += !consumed; state.generated++; }