diff options
author | Thomas Voss <mail@thomasvoss.com> | 2023-12-30 20:05:06 +0100 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2023-12-30 20:05:06 +0100 |
commit | 5fb26cffd50b0b226483663ad3a0c7608d4aacc9 (patch) | |
tree | 58fdefe7a6a0e4b5264ac96a828aee19ddc1db6b | |
parent | 14a1ff037694d1e56c1552fbbd15a4a6a3ae7a1d (diff) |
Improve NULL safety
-rw-r--r-- | cbs.h | 10 |
1 files changed, 8 insertions, 2 deletions
@@ -163,7 +163,9 @@ static void cmdclr(cmd_t *c); The cmdexecb() function is like cmdexec() except it writes the given commands standard output to the character buffer pointed to by p. It also stores the - size of the output in *n. The character buffer p is null-terminated. + size of the output in *n. The character buffer p is null-terminated. If the + given command produces no output to the standard output, p will be set to + NULL. cmdexec() and cmdexecb() have the same return values as cmdwait(). */ static int cmdexec(cmd_t); @@ -451,7 +453,8 @@ cmdexecb(cmd_t c, char **p, size_t *n) } close(fds[FD_R]); - buf[len] = 0; + if (buf) + buf[len] = 0; *p = buf; *n = len; return cmdwait(pid); @@ -628,6 +631,9 @@ pcquery(cmd_t *cmd, char *lib, int flags) diex("pkg-config terminated with exit-code %d", ec); } + if (!p) + return true; + /* Remove trailing newline */ p[n - 1] = 0; |