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

Thanks izabera for reporting this!
This commit is contained in:
Laslo Hunhold 2017-08-05 23:50:39 +02:00
parent ea8622a4ce
commit e92a1aef54
22 changed files with 24 additions and 23 deletions

View File

@ -17,7 +17,7 @@ main(int argc, char *argv[])
ssize_t off; ssize_t off;
char *p; char *p;
argv0 = argv[0], argc--, argv++; argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
if (argc != 1 && argc != 2) if (argc != 1 && argc != 2)
usage(); usage();

View File

@ -35,7 +35,7 @@ main(int argc, char *argv[])
.follow = 'P', .flags = 0 }; .follow = 'P', .flags = 0 };
size_t i; size_t i;
argv0 = argv[0], argc--, argv++; argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
for (; *argv && (*argv)[0] == '-'; argc--, argv++) { for (; *argv && (*argv)[0] == '-'; argc--, argv++) {
if (!(*argv)[1]) if (!(*argv)[1])

View File

@ -17,7 +17,7 @@ main(int argc, char *argv[])
char *shell[] = { "/bin/sh", "-i", NULL }, *aux, *cmd; char *shell[] = { "/bin/sh", "-i", NULL }, *aux, *cmd;
int savederrno; int savederrno;
argv0 = argv[0], argc--, argv++; argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
if (!argc) if (!argc)
usage(); usage();

View File

@ -97,7 +97,7 @@ main(int argc, char *argv[])
{ {
int fd; int fd;
argv0 = argv[0], argc--, argv++; argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
if (!argc) { if (!argc) {
cksum(0, NULL); cksum(0, NULL);

View File

@ -13,7 +13,7 @@ usage(void)
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
argv0 = argv[0], argc--, argv++; argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
if (argc != 1) if (argc != 1)
usage(); usage();

2
echo.c
View File

@ -8,7 +8,7 @@ main(int argc, char *argv[])
{ {
int nflag = 0; int nflag = 0;
argv0 = argv[0], argc--, argv++; argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
if (*argv && !strcmp(*argv, "-n")) { if (*argv && !strcmp(*argv, "-n")) {
nflag = 1; nflag = 1;

2
expr.c
View File

@ -257,7 +257,7 @@ main(int argc, char *argv[])
{ {
int ret; int ret;
argv0 = argv[0], argc--, argv++; argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
ret = !parse(argv, argc); ret = !parse(argv, argc);

View File

@ -16,7 +16,7 @@ main(int argc, char *argv[])
{ {
char host[HOST_NAME_MAX + 1]; char host[HOST_NAME_MAX + 1];
argv0 = argv[0], argc--, argv++; argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
if (!argc) { if (!argc) {
if (gethostname(host, sizeof(host)) < 0) if (gethostname(host, sizeof(host)) < 0)

3
kill.c
View File

@ -62,7 +62,8 @@ main(int argc, char *argv[])
size_t i; size_t i;
int ret = 0, sig = SIGTERM; int ret = 0, sig = SIGTERM;
argv0 = argv[0], argc--, argv++; argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
if (!argc) if (!argc)
usage(); usage();

2
link.c
View File

@ -12,7 +12,7 @@ usage(void)
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
argv0 = argv[0], argc--, argv++; argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
if (argc != 2) if (argc != 2)
usage(); usage();

View File

@ -15,7 +15,7 @@ main(int argc, char *argv[])
{ {
char *login; char *login;
argv0 = argv[0], argc--, argv++; argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
if (argc) if (argc)
usage(); usage();

View File

@ -19,7 +19,7 @@ main(int argc, char *argv[])
{ {
int fd, savederrno; int fd, savederrno;
argv0 = argv[0], argc--, argv++; argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
if (!argc) if (!argc)
usage(); usage();

View File

@ -12,7 +12,7 @@ main(int argc, char *argv[])
char *var; char *var;
int ret = 0; int ret = 0;
argv0 = argv[0], argc--, argv++; argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
if (!argc) { if (!argc) {
for (; *environ; environ++) for (; *environ; environ++)

View File

@ -15,7 +15,7 @@ main(int argc, char *argv[])
{ {
int savederrno; int savederrno;
argv0 = argv[0], argc--, argv++; argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
if (!argc) if (!argc)
usage(); usage();

View File

@ -14,7 +14,7 @@ main(int argc, char *argv[])
{ {
unsigned seconds; unsigned seconds;
argv0 = argv[0], argc--, argv++; argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
if (argc != 1) if (argc != 1)
usage(); usage();

View File

@ -17,7 +17,7 @@ main(int argc, char *argv[])
char tmp[] = "/tmp/sponge-XXXXXX"; char tmp[] = "/tmp/sponge-XXXXXX";
int fd, tmpfd; int fd, tmpfd;
argv0 = argv[0], argc--, argv++; argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
if (argc != 1) if (argc != 1)
usage(); usage();

2
sync.c
View File

@ -12,7 +12,7 @@ usage(void)
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
argv0 = argv[0], argc--, argv++; argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
if (argc) if (argc)
usage(); usage();

4
test.c
View File

@ -234,9 +234,9 @@ main(int argc, char *argv[])
int (*narg[])(char *[]) = { noarg, onearg, twoarg, threearg, fourarg }; int (*narg[])(char *[]) = { noarg, onearg, twoarg, threearg, fourarg };
size_t len; 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], "]")) if (len && argv0[--len] == '[' && (!len || argv0[--len] == '/') && strcmp(argv[--argc], "]"))
enprintf(2, "no matching ]\n"); enprintf(2, "no matching ]\n");

2
tty.c
View File

@ -15,7 +15,7 @@ main(int argc, char *argv[])
{ {
char *tty; char *tty;
argv0 = argv[0], argc--, argv++; argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
if (argc) if (argc)
usage(); usage();

View File

@ -12,7 +12,7 @@ usage(void)
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
argv0 = argv[0], argc--, argv++; argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
if (argc != 1) if (argc != 1)
usage(); usage();

View File

@ -18,7 +18,7 @@ main(int argc, char *argv[])
uid_t uid; uid_t uid;
struct passwd *pw; struct passwd *pw;
argv0 = argv[0], argc--, argv++; argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
if (argc) if (argc)
usage(); usage();

2
yes.c
View File

@ -8,7 +8,7 @@ main(int argc, char *argv[])
{ {
char **p; char **p;
argv0 = argv[0], argc--, argv++; argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
for (p = argv; ; p = (*p && *(p + 1)) ? p + 1 : argv) { for (p = argv; ; p = (*p && *(p + 1)) ? p + 1 : argv) {
fputs(*p ? *p : "y", stdout); fputs(*p ? *p : "y", stdout);