From 2e3394c5f9625ebb45a4d8e5608efd8018b47cbf Mon Sep 17 00:00:00 2001 From: ggb <55533232+haibaoo@users.noreply.github.com> Date: Mon, 16 Oct 2023 10:20:35 +0800 Subject: [PATCH] =?UTF-8?q?snprintf=E5=87=BD=E6=95=B0=E7=AC=AC=E4=BA=8C?= =?UTF-8?q?=E4=B8=AA=E5=8F=82=E6=95=B0=E5=BA=94=E8=AF=A5=E4=B8=BAbuf=5Flen?= =?UTF-8?q?=20+=201=20(#290)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### What problem were solved in this pull request? 计算程序名称时,snprintf函数第二个参数应该为buf_len + 1 --- deps/common/os/process.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/common/os/process.cpp b/deps/common/os/process.cpp index e0d434f76..1c46b5fd6 100644 --- a/deps/common/os/process.cpp +++ b/deps/common/os/process.cpp @@ -48,7 +48,7 @@ std::string get_process_name(const char *prog_name) std::cerr << "Failed to alloc memory for program name." << SYS_OUTPUT_FILE_POS << SYS_OUTPUT_ERROR << std::endl; return ""; } - snprintf(buf, buf_len, "%s", prog_name); + snprintf(buf, buf_len + 1, "%s", prog_name);//第二个参数需为buf_len + 1 process_name = basename(buf);