From 2a5de4e4476b7297e2f4e37b79ef9141a1829947 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Thu, 8 Feb 2024 22:10:39 +0100 Subject: [PATCH] Fix OOB access when computing -# tag for file without extension It is unlikely that this would ever come in practice, but there is no reason to fix it. Related to #2798 --- src/catch2/catch_test_case_info.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/catch2/catch_test_case_info.cpp b/src/catch2/catch_test_case_info.cpp index c38ee55a..2a4fbd33 100644 --- a/src/catch2/catch_test_case_info.cpp +++ b/src/catch2/catch_test_case_info.cpp @@ -85,8 +85,10 @@ namespace Catch { while (lastDot > 0 && filename[lastDot - 1] != '.') { --lastDot; } - --lastDot; + // In theory we could have filename without any extension in it + if ( lastDot == 0 ) { return StringRef(); } + --lastDot; size_t nameStart = lastDot; while (nameStart > 0 && filename[nameStart - 1] != '/' && filename[nameStart - 1] != '\\') { --nameStart;