diff --git a/base/BUILD.gn b/base/BUILD.gn index 452d3a61a9c7f1367fb201ddb3a490909f68d51e..6a579029c71fb9917c0d9215dda3f2e24f17ea24 100644 --- a/base/BUILD.gn +++ b/base/BUILD.gn @@ -19,6 +19,7 @@ declare_args() { c_utils_track_all = false c_utils_print_track_at_once = false c_utils_debug_log_enabled = false + c_utils_debug_intsan = false } config("utils_config") { @@ -144,6 +145,18 @@ ohos_shared_library("utils") { } else { sources = sources_utils configs = [ ":utils_coverage_config" ] + + if (c_utils_debug_intsan) { + sanitize = { + integer_overflow = true + debug = true + } + } else { + sanitize = { + integer_overflow = true + } + } + if (c_utils_debug_refbase) { configs += [ ":debug_refbase" ] if (c_utils_track_all) { diff --git a/base/src/string_ex.cpp b/base/src/string_ex.cpp index b279544be72336255a93c0006acb6f2bebeed0f8..abe32fdf2668c9715382c5d88767e85c58f4cea7 100644 --- a/base/src/string_ex.cpp +++ b/base/src/string_ex.cpp @@ -57,8 +57,16 @@ string ReplaceStr(const string& str, const string& src, const string& dst) string TrimStr(const string& str, const char cTrim /*= ' '*/) { string strTmp = str; - strTmp.erase(0, strTmp.find_first_not_of(cTrim)); - strTmp.erase(strTmp.find_last_not_of(cTrim) + sizeof(char)); + std::string::size_type firstBound = strTmp.find_first_not_of(cTrim); + std::string::size_type lastBound = strTmp.find_last_not_of(cTrim); + if (firstBound != std::string::npos) { + strTmp.erase(0, firstBound); + } + + if (lastBound != std::string::npos && lastBound != strTmp.size()) { + strTmp.erase(lastBound + sizeof(char)); + } + return strTmp; }