string-util: check for short input in previous_ansi_sequence()

ellipsize_mem() scans backwards for ANSI escape sequences and calls
previous_ansi_sequence(s, t - s, ...) as t walks down toward s. When
t reaches s + 1 the helper is invoked with length == 1 and computes
'length - 2', which wraps to SIZE_MAX - 1.

Follow-up for cb558ab222
This commit is contained in:
Luca Boccassi
2026-06-24 14:48:04 +01:00
parent 8168aca9fb
commit f66144cf2a
2 changed files with 17 additions and 0 deletions
+11
View File
@@ -9,6 +9,17 @@
#include "strv.h"
#include "tests.h"
TEST(ellipsize_mem_ansi_short) {
_cleanup_free_ char *a = ellipsize_mem("X\x1b[m", 4, 1, 50);
assert_se(a);
_cleanup_free_ char *b = ellipsize_mem(" \x1b[A", 4, 1, 0);
assert_se(b);
_cleanup_free_ char *c = ellipsize_mem("\x1b[m", 3, 1, 50);
assert_se(c);
}
TEST(xsprintf) {
char buf[5];