From 61c9fe44a3c31aaab14ec01c568ecf2f081e1bdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Sat, 4 Dec 2021 20:22:51 +0100 Subject: CGroupUtils: avoid unsigned integer underflow Do not underflow count at the last iteration, which triggers UBSAN when using -fsanitize=unsigned-integer-overflow. This is useful as those underflows can be a result of a flawed counting logic (e.g. a counter gets reduced more than increased). --- linux/CGroupUtils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'linux') diff --git a/linux/CGroupUtils.c b/linux/CGroupUtils.c index 6f3b6fe7..765012d3 100644 --- a/linux/CGroupUtils.c +++ b/linux/CGroupUtils.c @@ -33,7 +33,7 @@ static bool StrBuf_putc_write(StrBuf_state* p, char c) { } static bool StrBuf_putsn(StrBuf_state* p, StrBuf_putc_t w, const char* s, size_t count) { - while (count--) + for (; count; count--) if (!w(p, *s++)) return false; -- cgit v1.2.3