From 711ad817afaf461abd3c50dbd40d6d8dce416da6 Mon Sep 17 00:00:00 2001 From: wenlong12 Date: Wed, 23 Feb 2022 16:01:37 +0800 Subject: [PATCH] fix bytrace Infinite loop issue Signed-off-by: wenlong12 Signed-off-by: wenlong12 --- bin/src/bytrace.cpp | 12 +++++++++--- bin/test/unittest/common/native/bytrace_ndk_test.cpp | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/bin/src/bytrace.cpp b/bin/src/bytrace.cpp index 3f6bb59..81304d2 100755 --- a/bin/src/bytrace.cpp +++ b/bin/src/bytrace.cpp @@ -177,9 +177,15 @@ static string CanonicalizeSpecPath(const char* src) return ""; } #else - if (realpath(src, resolvedPath) == nullptr) { - fprintf(stderr, "Error: _fullpath %s failed", src); - return ""; + if (access(src, F_OK) == 0) { + if (realpath(src, resolvedPath) == nullptr) { + fprintf(stderr, "Error: _fullpath %s failed", src); + return ""; + } + } else { + if (sprintf_s(resolvedPath, PATH_MAX, "%s", src) == -1) { + return ""; + } } #endif string res(resolvedPath); diff --git a/bin/test/unittest/common/native/bytrace_ndk_test.cpp b/bin/test/unittest/common/native/bytrace_ndk_test.cpp index 3430172..b0d5f35 100755 --- a/bin/test/unittest/common/native/bytrace_ndk_test.cpp +++ b/bin/test/unittest/common/native/bytrace_ndk_test.cpp @@ -283,7 +283,7 @@ MyTrace GetTraceResult(const string& checkContent, const vector& list) regex pattern(checkContent); smatch match; Param param {""}; - for (unsigned int i = list.size() - 1; i >= 0; i--) { + for (int i = list.size() - 1; i >= 0; i--) { if (regex_match(list[i], match, pattern)) { param.m_task = match[TASK]; param.m_tid = match[TID];