From: Mark Wooding Date: Fri, 16 Nov 2018 18:03:38 +0000 (+0000) Subject: sys/t/mdup-test.c: Cope with the idea of arguments which aren't fd pairs. X-Git-Tag: 2.3.3~7 X-Git-Url: https://git.distorted.org.uk/~mdw/mLib/commitdiff_plain/7ff43cd7273904110681588929bcbad89b28227b sys/t/mdup-test.c: Cope with the idea of arguments which aren't fd pairs. The code used to assume a fixed relationship between command-line argument indices and indices in the `mdup_fd' table. Fix this by introducing separate index variables in the argument-parsing loop, and set the table length correctly afterwards. --- diff --git a/sys/t/mdup-test.c b/sys/t/mdup-test.c index 3169247..ef9429d 100644 --- a/sys/t/mdup-test.c +++ b/sys/t/mdup-test.c @@ -14,7 +14,7 @@ static void fail(const char *what) { perror(what); exit(1); } int main(int argc, char *argv[]) { - int i, n; + int i, n, j; int fd, fd2; struct stat st; int ino[MAXFD]; @@ -22,13 +22,14 @@ int main(int argc, char *argv[]) mdup_fd fds[MAXFD]; int win = 1; - for (i = 0; i < argc - 1; i++) { - if (i >= MAXFD) { fprintf(stderr, "too many\n"); exit(1); } - if (sscanf(argv[i + 1], "%d:%d", &fds[i].cur, &fds[i].want) < 2 || - fds[i].cur >= MAXFD) + for (i = 1, j = 0; i < argc; i++) { + if (j >= MAXFD) { fprintf(stderr, "too many\n"); exit(1); } + if (sscanf(argv[i], "%d:%d", &fds[j].cur, &fds[j].want) < 2 || + fds[j].cur >= MAXFD) { fprintf(stderr, "bad syntax\n"); exit(1); } + j++; } - n = argc - 1; + n = j; for (i = 0; i < MAXFD; i++) flag[i] = -1; for (i = 0; i < n; i++) { fd = fds[i].cur;