scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 8379c7f20b9346a7cd69808c58661bfc2e0d39f5
parent 6b12fb5f80c2cbdc77f4a6bdb236469986921502
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sat, 30 Oct 2021 12:27:10 +0200

driver/posix: Revert check in snprintf()

Commit 0e40771ad1 removed the check for negative values
in snprintf(), and that check is actually needed in you
follow the standard.

Diffstat:
Msrc/cmd/cc/posix/cc.c | 6+++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/cmd/cc/posix/cc.c b/src/cmd/cc/posix/cc.c @@ -183,12 +183,12 @@ inittool(int tool) case CC2: fmt = cc12fmt(tool); n = snprintf(t->bin, sizeof(t->bin), fmt, t->cmd, arch, abi); - if (n >= sizeof(t->bin)) + if (n < 0 || n >= sizeof(t->bin)) die("cc: target tool name is too long"); case QBE: n = snprintf(t->cmd, sizeof(t->cmd), "%s/libexec/scc/%s", prefix, t->bin); - if (n >= sizeof(t->cmd)) + if (n < 0 || n >= sizeof(t->cmd)) die("cc: target tool path is too long"); break; case LD: @@ -242,7 +242,7 @@ outfname(char *path, char *type) newsz = pathln + 1 + strlen(type) + 1; new = xmalloc(newsz); n = snprintf(new, newsz, "%.*s%c%s", (int)pathln, path, sep, type); - if (n >= newsz) + if (n < 0 || n >= newsz) die("cc: wrong output filename"); if (sep == '/') { if ((tmpfd = mkstemp(new)) < 0)