On Wed, Sep 16, 2026 at 07:38:09PM +0200, Jonas Rebmann wrote:
> Although all of the available sequences expand to exactly one byte, the
> current implementation decrements the remaining bytes in the destination
> buffer twice, effectively shortening it by one byte per each unescaped
> character.
> 
> The extra decrement is only needed in the one case where a single loop
> iteration produces two output bytes: when the sequence turns out not to
> be a valid escape sequence, the previously skipped backslash has to be
> emitted before the character is copied verbatim.
> 
> Add a kunit regression-test that unescapes into a barely long enough 3
> buffer.

Can you add a simple example here with the hexdump to show the point?
Yes, reading the code helps, but the above commit message is a bit
unclear (at least to me).

> Fixes: 16c7fa05829e ("lib/string_helpers: introduce generic string_unescape")
> Signed-off-by: Jonas Rebmann <[email protected]>

...

> +     test_string_unescape_one(test, "short buffer", UNESCAPE_HEX, 
> "\\x41\\x41B", 4, "AAB", 3);
> +     test_string_unescape_one(test, "unrecognized escape at end", 
> UNESCAPE_HEX, "B\\qX", 4, "B\\q", 3);

Still wondering if we can incorporate this into the "combined" loop?

-- 
With Best Regards,
Andy Shevchenko



Reply via email to