Fix overflow
Static analysis correctly notes that in the case of empty string, this
can overflow. Given that this is coming from a constexpr expression,
that would be impossible in practice, but having static analysis pass is
helpful.
Refactor the code to account for index overflows.
Tested: Code compiles
Change-Id: I00a1e0661182a6fb15acd6822faabcc0ff8191b7
Signed-off-by: Ed Tanous <etanous@nvidia.com>
diff --git a/http/logging.hpp b/http/logging.hpp
index 768014a..55f239f 100644
--- a/http/logging.hpp
+++ b/http/logging.hpp
@@ -77,7 +77,11 @@
"Missing string for level");
constexpr std::string_view levelString = mapLogLevelFromName[stringIndex];
std::string_view filename = loc.file_name();
- filename = filename.substr(filename.rfind('/') + 1);
+ filename = filename.substr(filename.rfind('/'));
+ if (!filename.empty())
+ {
+ filename.remove_prefix(1);
+ }
std::string logLocation;
try
{