From 65cdf19262f97ac944246c05e85b5e24c47602b6 Mon Sep 17 00:00:00 2001 From: jason Date: Mon, 8 Jan 2024 14:35:07 +0000 Subject: [PATCH] fix(ndk): remove the use of `substr` from `bsg_check_invalid_libname` --- .../src/main/jni/utils/stack_unwinder.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/bugsnag-plugin-android-ndk/src/main/jni/utils/stack_unwinder.cpp b/bugsnag-plugin-android-ndk/src/main/jni/utils/stack_unwinder.cpp index f0299e894b..b1f9286979 100644 --- a/bugsnag-plugin-android-ndk/src/main/jni/utils/stack_unwinder.cpp +++ b/bugsnag-plugin-android-ndk/src/main/jni/utils/stack_unwinder.cpp @@ -39,12 +39,17 @@ static void bsg_fallback_symbols(const uint64_t addr, } static bool bsg_check_invalid_libname(const std::string &filename) { + const auto length = filename.length(); return filename.empty() || // if the filename ends-in ".apk" then the lib was loaded without // extracting it from the apk we consider these as "invalid" to trigger // the use of a fallback filename - (filename.length() >= 4 && - filename.substr(filename.length() - 4, 4) == ".apk"); + (length >= 4 && + // compare char-by-char to avoid the allocation is substr + filename[length - 4] == '.' && + filename[length - 3] == 'a' && + filename[length - 2] == 'p' && + filename[length - 1] == 'k'); } void bsg_unwinder_init() {