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;
char *p;
argv0 = argv[0], argc--, argv++;
argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
if (argc != 1 && argc != 2)
usage();

View File

@ -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])

View File

@ -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();

View File

@ -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);

View File

@ -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();

2
echo.c
View File

@ -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;

2
expr.c
View File

@ -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);

View File

@ -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)

3
kill.c
View File

@ -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();

2
link.c
View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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++)

View File

@ -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();

View File

@ -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();

View File

@ -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();

2
sync.c
View File

@ -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();

4
test.c
View File

@ -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");

2
tty.c
View File

@ -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();

View File

@ -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();

View File

@ -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();

2
yes.c
View File

@ -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);