From 09462bda7f8da4e59307e0d6a7446d499c1da34c Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Tue, 2 Jul 2024 12:22:29 +0200 Subject: [PATCH] Avoid upos underflowing in match loop --- ext/yahttp/yahttp/router.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ext/yahttp/yahttp/router.cpp b/ext/yahttp/yahttp/router.cpp index fdf23a45c5..5f6885a887 100644 --- a/ext/yahttp/yahttp/router.cpp +++ b/ext/yahttp/yahttp/router.cpp @@ -62,8 +62,15 @@ namespace YaHTTP { } nend = upos; params[pname] = funcptr::tie(nstart, nend); - - upos--; + if (upos > 0) { + upos--; + } + else { + // If upos is zero, do not decrement it and then increment at bottom of loop, this disturbs Coverity. + // Only increment rpos and continue loop + rpos++; + continue; + } } else if (route[rpos] != requrl.path[upos]) { break; -- 2.47.2