From e1efe942da439d9434cc67dc6f2d129fcaa4d5f3 Mon Sep 17 00:00:00 2001 From: groot Date: Mon, 29 Apr 2019 16:34:43 +0800 Subject: [PATCH] fix test load config failure Former-commit-id: 7781b6ff8a4c1d72dfe4f872a7765424af40286e --- cpp/src/utils/CommonUtil.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/cpp/src/utils/CommonUtil.cpp b/cpp/src/utils/CommonUtil.cpp index 86bb3797ac..083df0db73 100644 --- a/cpp/src/utils/CommonUtil.cpp +++ b/cpp/src/utils/CommonUtil.cpp @@ -133,19 +133,21 @@ bool CommonUtil::IsFileExist(const std::string &path) { } std::string CommonUtil::GetExePath() { - const size_t bug_len = 1024; - char exe_path[bug_len]; - size_t cnt = readlink("/proc/self/exe", exe_path, bug_len); - if(cnt < 0|| cnt >= bug_len) { + const size_t buf_len = 1024; + char buf[buf_len]; + size_t cnt = readlink("/proc/self/exe", buf, buf_len); + if(cnt < 0|| cnt >= buf_len) { return ""; } - std::string store_path = exe_path; - if(store_path.rfind('/') != store_path.length()){ - std::string sub_str = store_path.substr(0, store_path.rfind('/')); + buf[cnt] = '\0'; + + std::string exe_path = buf; + if(exe_path.rfind('/') != exe_path.length()){ + std::string sub_str = exe_path.substr(0, exe_path.rfind('/')); return sub_str + "/"; } - return store_path; + return exe_path; } }