From d18fbac2e3838f4e64a969a35fafe752f3ca978c Mon Sep 17 00:00:00 2001 From: Matthew House Date: Wed, 22 Jan 2025 19:19:50 -0500 Subject: [PATCH] Add null terminator to get_from_pipe output --- sysdeps/linux/glibtop_private.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sysdeps/linux/glibtop_private.c b/sysdeps/linux/glibtop_private.c index 18cb7a6e..8d170b5e 100644 --- a/sysdeps/linux/glibtop_private.c +++ b/sysdeps/linux/glibtop_private.c @@ -65,8 +65,13 @@ get_from_pipe (char *buffer, const size_t bufsiz, const char *cmd) fp = popen (cmd, "r"); size_t psize = fread(buffer,1,bufsiz,fp); - if (psize == bufsiz) + + if (psize == bufsiz) { g_warning("Read bufsiz bytes, there may be more"); + buffer [bufsiz - 1] = '\0'; + } else { + buffer [psize] = '\0'; + } pclose (fp); } -- GitLab