浏览代码

libobs: Fix os_get_executable_path_ptr on Linux

Terminate a non-terminated string generated by readlink()
to pass to dirname() that needs terminated string as a parameter.
Masato Takahashi 5 年之前
父节点
当前提交
4ded3b39fd
共有 1 个文件被更改,包括 4 次插入1 次删除
  1. 4 1
      libobs/util/platform-nix.c

+ 4 - 1
libobs/util/platform-nix.c

@@ -287,7 +287,10 @@ char *os_get_executable_path_ptr(const char *name)
 	}
 	count = pathlen;
 #else
-	ssize_t count = readlink("/proc/self/exe", exe, PATH_MAX);
+	ssize_t count = readlink("/proc/self/exe", exe, PATH_MAX - 1);
+	if (count >= 0) {
+		exe[count] = '\0';
+	}
 #endif
 	const char *path_out = NULL;
 	struct dstr path;