mirror of
https://github.com/matrix-construct/construct
synced 2024-12-27 07:54:05 +01:00
ircd::spirit: Improve generator overflow counting.
This commit is contained in:
parent
be07ae05b2
commit
268d4265ca
1 changed files with 9 additions and 2 deletions
|
@ -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<class gen,
|
||||
|
@ -298,17 +301,20 @@ ircd::generate(mutable_buffer &out,
|
|||
karma::generate(sink, std::forward<gen>(g), std::forward<attr>(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++;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue