diff --git a/usr.bin/sdiff/sdiff.c b/usr.bin/sdiff/sdiff.c --- a/usr.bin/sdiff/sdiff.c +++ b/usr.bin/sdiff/sdiff.c @@ -8,7 +8,6 @@ #include <sys/param.h> #include <sys/queue.h> #include <sys/stat.h> -#include <sys/types.h> #include <sys/wait.h> #include <ctype.h> @@ -228,7 +227,7 @@ * waste some memory; however we need an extra space for the * NULL at the end, so it sort of works out. */ - if (!(diffargv = calloc(argc, sizeof(char **) * 2))) + if (!(diffargv = calloc(argc, sizeof(char *) * 2))) err(2, "main"); /* Add first argument, the program name. */ @@ -376,21 +375,18 @@ if (pipe(fd)) err(2, "pipe"); - switch (pid = fork()) { - case 0: + if ((pid = fork()) < 0) + err(1, "fork()"); + if (pid == 0) { /* child */ /* We don't read from the pipe. */ close(fd[0]); - if (dup2(fd[1], STDOUT_FILENO) == -1) - err(2, "child could not duplicate descriptor"); + if (dup2(fd[1], STDOUT_FILENO) != STDOUT_FILENO) + _exit(2); /* Free unused descriptor. */ close(fd[1]); execvp(diffprog, diffargv); - err(2, "could not execute diff: %s", diffprog); - break; - case -1: - err(2, "could not fork"); - break; + _exit(2); } /* parent */ @@ -569,7 +565,7 @@ const char *p; /* Skip leading whitespace. */ - for (p = cmd; isspace(*p); ++p) + for (p = cmd; isspace((unsigned char)*p); ++p) ; switch (*p) { case 'e': @@ -719,7 +715,7 @@ p = line; /* Go to character after line number. */ - while (isdigit(*p)) + while (isdigit((unsigned char)*p)) ++p; c = *p; *p++ = 0; @@ -731,7 +727,7 @@ if (c == ',') { q = p; /* Go to character after file2end. */ - while (isdigit(*p)) + while (isdigit((unsigned char)*p)) ++p; c = *p; *p++ = 0; @@ -750,7 +746,7 @@ q = p; /* Go to character after line number. */ - while (isdigit(*p)) + while (isdigit((unsigned char)*p)) ++p; c = *p; *p++ = 0;