string-util: allow taking SIZE_MAX as size to shorten to
This is useful for two reasons: 1. it addresses a potential overflow in a graceful way 2. Gives callers the ability to just pass SIZE_MAX for a NOP Prompted by: #31341
This commit is contained in:
committed by
Luca Boccassi
parent
10d50d9eac
commit
d49dc7bbe7
@@ -299,8 +299,13 @@ TEST(ascii_strlower) {
|
||||
TEST(strshorten) {
|
||||
char s[] = "foobar";
|
||||
|
||||
assert_se(strlen(strshorten(s, SIZE_MAX)) == 6);
|
||||
assert_se(strlen(strshorten(s, SIZE_MAX-1)) == 6);
|
||||
assert_se(strlen(strshorten(s, SIZE_MAX-2)) == 6);
|
||||
assert_se(strlen(strshorten(s, 6)) == 6);
|
||||
assert_se(strlen(strshorten(s, 7)) == 6);
|
||||
assert_se(strlen(strshorten(s, 12)) == 6);
|
||||
assert_se(strlen(strshorten(s, 5)) == 5);
|
||||
assert_se(strlen(strshorten(s, 2)) == 2);
|
||||
assert_se(strlen(strshorten(s, 0)) == 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user