From f09e6e909b5afa22a5d7d395861004c3bbc14fd9 Mon Sep 17 00:00:00 2001 From: Niklas Eiling Date: Tue, 31 Oct 2023 15:53:42 +0100 Subject: [PATCH] fix possible segfault due to non-functional range check with unsigned int Signed-off-by: Niklas Eiling --- lib/node.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/node.cpp b/lib/node.cpp index 483573e9a..f55789fe0 100644 --- a/lib/node.cpp +++ b/lib/node.cpp @@ -310,16 +310,17 @@ int Node::write(struct Sample *smps[], unsigned cnt) { #ifdef WITH_HOOKS // Run write hooks - cnt = out.hooks.process(smps, cnt); - if (cnt <= 0) - return cnt; + int hook_cnt = out.hooks.process(smps, cnt); + if (hook_cnt <= 0) + return hook_cnt; + cnt = hook_cnt; #endif // WITH_HOOKS vect = getFactory()->getVectorize(); if (!vect) vect = cnt; - while (cnt - nsent > 0) { + while (cnt > static_cast(nsent)) { tosend = MIN(cnt - nsent, vect); sent = _write(&smps[nsent], tosend); if (sent < 0)