sbase

suckless unix tools
git clone git://git.suckless.org/sbase
Log | Files | Refs | README | LICENSE

commit e92a1aef54570e86d778da84847e6d8d9e924487
parent ea8622a4ce21e414050e116542cb76581d40d27a
Author: Laslo Hunhold <dev@frign.de>
Date:   Sat,  5 Aug 2017 23:50:39 +0200

Handle { NULL } argv[] properly in manual arg-reduction

Thanks izabera for reporting this!

Diffstat:
basename.c | 2+-
chmod.c | 2+-
chroot.c | 2+-
cksum.c | 2+-
dirname.c | 2+-
echo.c | 2+-
expr.c | 2+-
hostname.c | 2+-
kill.c | 3++-
link.c | 2+-
logname.c | 2+-
nohup.c | 2+-
printenv.c | 2+-
setsid.c | 2+-
sleep.c | 2+-
sponge.c | 2+-
sync.c | 2+-
test.c | 4++--
tty.c | 2+-
unlink.c | 2+-
whoami.c | 2+-
yes.c | 2+-
22 files changed, 24 insertions(+), 23 deletions(-)

diff --git a/basename.c b/basename.c @@ -17,7 +17,7 @@ main(int argc, char *argv[]) ssize_t off; char *p; - argv0 = argv[0], argc--, argv++; + argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0; if (argc != 1 && argc != 2) usage(); diff --git a/chmod.c b/chmod.c @@ -35,7 +35,7 @@ main(int argc, char *argv[]) .follow = 'P', .flags = 0 }; size_t i; - argv0 = argv[0], argc--, argv++; + argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0; for (; *argv && (*argv)[0] == '-'; argc--, argv++) { if (!(*argv)[1]) diff --git a/chroot.c b/chroot.c @@ -17,7 +17,7 @@ main(int argc, char *argv[]) char *shell[] = { "/bin/sh", "-i", NULL }, *aux, *cmd; int savederrno; - argv0 = argv[0], argc--, argv++; + argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0; if (!argc) usage(); diff --git a/cksum.c b/cksum.c @@ -97,7 +97,7 @@ main(int argc, char *argv[]) { int fd; - argv0 = argv[0], argc--, argv++; + argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0; if (!argc) { cksum(0, NULL); diff --git a/dirname.c b/dirname.c @@ -13,7 +13,7 @@ usage(void) int main(int argc, char *argv[]) { - argv0 = argv[0], argc--, argv++; + argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0; if (argc != 1) usage(); diff --git a/echo.c b/echo.c @@ -8,7 +8,7 @@ main(int argc, char *argv[]) { int nflag = 0; - argv0 = argv[0], argc--, argv++; + argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0; if (*argv && !strcmp(*argv, "-n")) { nflag = 1; diff --git a/expr.c b/expr.c @@ -257,7 +257,7 @@ main(int argc, char *argv[]) { int ret; - argv0 = argv[0], argc--, argv++; + argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0; ret = !parse(argv, argc); diff --git a/hostname.c b/hostname.c @@ -16,7 +16,7 @@ main(int argc, char *argv[]) { char host[HOST_NAME_MAX + 1]; - argv0 = argv[0], argc--, argv++; + argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0; if (!argc) { if (gethostname(host, sizeof(host)) < 0) diff --git a/kill.c b/kill.c @@ -62,7 +62,8 @@ main(int argc, char *argv[]) size_t i; int ret = 0, sig = SIGTERM; - argv0 = argv[0], argc--, argv++; + argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0; + if (!argc) usage(); diff --git a/link.c b/link.c @@ -12,7 +12,7 @@ usage(void) int main(int argc, char *argv[]) { - argv0 = argv[0], argc--, argv++; + argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0; if (argc != 2) usage(); diff --git a/logname.c b/logname.c @@ -15,7 +15,7 @@ main(int argc, char *argv[]) { char *login; - argv0 = argv[0], argc--, argv++; + argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0; if (argc) usage(); diff --git a/nohup.c b/nohup.c @@ -19,7 +19,7 @@ main(int argc, char *argv[]) { int fd, savederrno; - argv0 = argv[0], argc--, argv++; + argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0; if (!argc) usage(); diff --git a/printenv.c b/printenv.c @@ -12,7 +12,7 @@ main(int argc, char *argv[]) char *var; int ret = 0; - argv0 = argv[0], argc--, argv++; + argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0; if (!argc) { for (; *environ; environ++) diff --git a/setsid.c b/setsid.c @@ -15,7 +15,7 @@ main(int argc, char *argv[]) { int savederrno; - argv0 = argv[0], argc--, argv++; + argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0; if (!argc) usage(); diff --git a/sleep.c b/sleep.c @@ -14,7 +14,7 @@ main(int argc, char *argv[]) { unsigned seconds; - argv0 = argv[0], argc--, argv++; + argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0; if (argc != 1) usage(); diff --git a/sponge.c b/sponge.c @@ -17,7 +17,7 @@ main(int argc, char *argv[]) char tmp[] = "/tmp/sponge-XXXXXX"; int fd, tmpfd; - argv0 = argv[0], argc--, argv++; + argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0; if (argc != 1) usage(); diff --git a/sync.c b/sync.c @@ -12,7 +12,7 @@ usage(void) int main(int argc, char *argv[]) { - argv0 = argv[0], argc--, argv++; + argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0; if (argc) usage(); diff --git a/test.c b/test.c @@ -234,9 +234,9 @@ main(int argc, char *argv[]) int (*narg[])(char *[]) = { noarg, onearg, twoarg, threearg, fourarg }; size_t len; - argv0 = argv[0], argc--, argv++; + argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0; - len = strlen(argv0); + len = argv0 ? strlen(argv0) : 0; if (len && argv0[--len] == '[' && (!len || argv0[--len] == '/') && strcmp(argv[--argc], "]")) enprintf(2, "no matching ]\n"); diff --git a/tty.c b/tty.c @@ -15,7 +15,7 @@ main(int argc, char *argv[]) { char *tty; - argv0 = argv[0], argc--, argv++; + argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0; if (argc) usage(); diff --git a/unlink.c b/unlink.c @@ -12,7 +12,7 @@ usage(void) int main(int argc, char *argv[]) { - argv0 = argv[0], argc--, argv++; + argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0; if (argc != 1) usage(); diff --git a/whoami.c b/whoami.c @@ -18,7 +18,7 @@ main(int argc, char *argv[]) uid_t uid; struct passwd *pw; - argv0 = argv[0], argc--, argv++; + argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0; if (argc) usage(); diff --git a/yes.c b/yes.c @@ -8,7 +8,7 @@ main(int argc, char *argv[]) { char **p; - argv0 = argv[0], argc--, argv++; + argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0; for (p = argv; ; p = (*p && *(p + 1)) ? p + 1 : argv) { fputs(*p ? *p : "y", stdout);