From daba307035faf4cc01f1ccb883b21281d91234cc Mon Sep 17 00:00:00 2001 From: Ralf Baechle Date: Fri, 28 Jul 2017 14:10:07 +0200 Subject: treewide: Kill assignments in if conditions. Somewhat hard to read and the code base already has many overlong lines. Found with below spatch file and some manual editing in ax25/access.c to restore a comment lost by spatch. @parens@ expression E, F, G; binary operator X; statement S; @@ - if ((E = F) X G) + E = F; + if (E X G) S Signed-off-by: Ralf Baechle --- kiss/kissattach.c | 33 ++++++++++++++++++++++----------- kiss/kissnetd.c | 3 ++- kiss/kissparms.c | 3 ++- kiss/mkiss.c | 21 ++++++++++++++------- kiss/net2kiss.c | 17 +++++++++++------ 5 files changed, 51 insertions(+), 26 deletions(-) (limited to 'kiss') diff --git a/kiss/kissattach.c b/kiss/kissattach.c index 9667da1..2b05956 100644 --- a/kiss/kissattach.c +++ b/kiss/kissattach.c @@ -68,7 +68,8 @@ static int readconfig(char *port) char buffer[90], *s; int n = 0; - if ((fp = fopen(CONF_AXPORTS_FILE, "r")) == NULL) { + fp = fopen(CONF_AXPORTS_FILE, "r"); + if (fp == NULL) { fprintf(stderr, "%s: cannot open axports file %s\n", progname, CONF_AXPORTS_FILE); return FALSE; @@ -77,13 +78,15 @@ static int readconfig(char *port) while (fgets(buffer, 90, fp) != NULL) { n++; - if ((s = strchr(buffer, '\n')) != NULL) + s = strchr(buffer, '\n'); + if (s != NULL) *s = '\0'; if (*buffer == 0 || *buffer == '#') continue; - if ((s = strtok(buffer, " \t\r\n")) == NULL) { + s = strtok(buffer, " \t\r\n"); + if (s == NULL) { fprintf(stderr, "%s: unable to parse line %d of the axports file\n", progname, n); return FALSE; } @@ -91,27 +94,31 @@ static int readconfig(char *port) if (strcmp(s, port) != 0) continue; - if ((s = strtok(NULL, " \t\r\n")) == NULL) { + s = strtok(NULL, " \t\r\n"); + if (s == NULL) { fprintf(stderr, "%s: unable to parse line %d of the axports file\n", progname, n); return FALSE; } callsign = strdup(s); - if ((s = strtok(NULL, " \t\r\n")) == NULL) { + s = strtok(NULL, " \t\r\n"); + if (s == NULL) { fprintf(stderr, "%s: unable to parse line %d of the axports file\n", progname, n); return FALSE; } speed = atoi(s); - if ((s = strtok(NULL, " \t\r\n")) == NULL) { + s = strtok(NULL, " \t\r\n"); + if (s == NULL) { fprintf(stderr, "%s: unable to parse line %d of the axports file\n", progname, n); return FALSE; } if (mtu == 0) { - if ((mtu = atoi(s)) <= 0) { + mtu = atoi(s); + if (mtu <= 0) { fprintf(stderr, "%s: invalid paclen setting\n", progname); return FALSE; } @@ -153,7 +160,8 @@ static int startiface(char *dev, struct hostent *hp) struct ifreq ifr; int fd; - if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { + fd = socket(AF_INET, SOCK_DGRAM, 0); + if (fd < 0) { fprintf(stderr, "%s: ", progname); perror("socket"); return FALSE; @@ -248,7 +256,8 @@ int main(int argc, char *argv[]) logging = TRUE; break; case 'm': - if ((mtu = atoi(optarg)) <= 0) { + mtu = atoi(optarg); + if (mtu <= 0) { fprintf(stderr, "%s: invalid mtu size - %s\n", progname, optarg); return 1; } @@ -296,7 +305,8 @@ int main(int argc, char *argv[]) return 1; } - if ((fd = open(kttyname, O_RDONLY | O_NONBLOCK)) == -1) { + fd = open(kttyname, O_RDONLY | O_NONBLOCK); + if (fd == -1) { if (errno == ENOENT) { fprintf(stderr, "%s: Cannot find serial device %s, no such file or directory.\n", progname, kttyname); } else { @@ -308,7 +318,8 @@ int main(int argc, char *argv[]) if (i_am_unix98_pty_master) { /* get name of pts-device */ - if ((namepts = ptsname(fd)) == NULL) { + namepts = ptsname(fd); + if (namepts == NULL) { fprintf(stderr, "%s: Cannot get name of pts-device.\n", progname); return 1; } diff --git a/kiss/kissnetd.c b/kiss/kissnetd.c index abf9ee9..b0692df 100644 --- a/kiss/kissnetd.c +++ b/kiss/kissnetd.c @@ -131,7 +131,8 @@ static void ReopenPort(int PortNumber) if (!strcmp(PortList[PortNumber]->Name, "/dev/ptmx")) { char *npts; /* get name of pts-device */ - if ((npts = ptsname(PortList[PortNumber]->Fd)) == NULL) { + npts = ptsname(PortList[PortNumber]->Fd); + if (npts == NULL) { sprintf(MyString, "Cannot get name of pts-device.\n"); syslog(LOG_WARNING, "kissnetd : Cannot get name of pts-device\n"); exit(1); diff --git a/kiss/kissparms.c b/kiss/kissparms.c index def7b59..7834162 100644 --- a/kiss/kissparms.c +++ b/kiss/kissparms.c @@ -153,7 +153,8 @@ int main(int argc, char *argv[]) return 1; } - if ((s = socket(PF_PACKET, SOCK_PACKET, htons(proto))) < 0) { + s = socket(PF_PACKET, SOCK_PACKET, htons(proto)); + if (s < 0) { perror("kissparms: socket"); return 1; } diff --git a/kiss/mkiss.c b/kiss/mkiss.c index 35e7ed0..1747c33 100644 --- a/kiss/mkiss.c +++ b/kiss/mkiss.c @@ -510,12 +510,14 @@ int main(int argc, char *argv[]) * non-blocking so it won't block regardless of the modem * status lines. */ - if ((tty = calloc(1, sizeof(struct iface))) == NULL) { + tty = calloc(1, sizeof(struct iface)); + if (tty == NULL) { perror("mkiss: malloc"); return 1; } - if ((tty->fd = open(argv[optind], O_RDWR | O_NDELAY)) == -1) { + tty->fd = open(argv[optind], O_RDWR | O_NDELAY); + if (tty->fd == -1) { perror("mkiss: open"); return 1; } @@ -542,7 +544,8 @@ int main(int argc, char *argv[]) static char name_ptmx[] = "/dev/ptmx"; char *pty_name = (i < numptys ? argv[optind+i+1] : name_ptmx); - if ((pty[i] = calloc(1, sizeof(struct iface))) == NULL) { + pty[i] = calloc(1, sizeof(struct iface)); + if (pty[i] == NULL) { perror("mkiss: malloc"); return 1; } @@ -550,7 +553,8 @@ int main(int argc, char *argv[]) pty[i]->fd = -1; strcpy(pty[i]->namepts, "none"); } else { - if ((pty[i]->fd = open(pty_name, O_RDWR)) == -1) { + pty[i]->fd = open(pty_name, O_RDWR); + if (pty[i]->fd == -1) { perror("mkiss: open"); free(pty[i]); pty[i] = NULL; @@ -564,7 +568,8 @@ int main(int argc, char *argv[]) pty[i]->optr = pty[i]->obuf; if (!strcmp(pty[i]->name, "/dev/ptmx")) { /* get name of pts-device */ - if ((npts = ptsname(pty[i]->fd)) == NULL) { + npts = ptsname(pty[i]->fd); + if (npts == NULL) { fprintf(stderr, "mkiss: Cannot get name of pts-device.\n"); free(pty[i]); pty[i] = NULL; @@ -672,7 +677,8 @@ int main(int argc, char *argv[]) break; } for (icp = ibuf; size > 0; size--, icp++) { - if ((len = kiss_rx(tty, *icp, crcflag)) != 0) { + len = kiss_rx(tty, *icp, crcflag); + if (len != 0) { if ((i = (*tty->obuf & 0xF0) >> 4) < numptys) { if (pty[i]->fd != -1) { kiss_tx(pty[i]->fd, 0, tty->obuf, len, FALSE); @@ -698,7 +704,8 @@ int main(int argc, char *argv[]) goto end; } for (icp = ibuf; size > 0; size--, icp++) { - if ((len = kiss_rx(pty[i], *icp, FALSE)) != 0) { + len = kiss_rx(pty[i], *icp, FALSE); + if (len != 0) { kiss_tx(tty->fd, i, pty[i]->obuf, len, crcflag); tty->txpackets++; tty->txbytes += len; diff --git a/kiss/net2kiss.c b/kiss/net2kiss.c index 1c1b50d..d9e8ff5 100644 --- a/kiss/net2kiss.c +++ b/kiss/net2kiss.c @@ -258,7 +258,8 @@ static int openpty(int *amaster, int *aslave, char *name, #if 0 (void) revoke(line); #endif - if ((slave = open(line, O_RDWR, 0)) != -1) { + slave = open(line, O_RDWR, 0); + if (slave != -1) { *amaster = master; *aslave = slave; if (name) @@ -596,8 +597,8 @@ int main(int argc, char *argv[]) slavename[5] = 'p'; master_name = slavename; } else { - if ((fdpty = open(name_pname, - O_RDWR | O_NOCTTY | O_NONBLOCK)) < 0) { + fdpty = open(name_pname, O_RDWR | O_NOCTTY | O_NONBLOCK); + if (fdpty < 0) { fprintf(stderr, "%s: cannot open \"%s\"\n", progname, name_pname); exit(1); @@ -606,7 +607,8 @@ int main(int argc, char *argv[]) i_am_unix98_pty_master = 1; master_name = name_pname; } - if ((fdif = socket(PF_INET, SOCK_PACKET, proto)) < 0) + fdif = socket(PF_INET, SOCK_PACKET, proto); + if (fdif < 0) die("socket"); memset(&sa, 0, sizeof(struct sockaddr)); memcpy(sa.sa_data, name_iface, sizeof(sa.sa_data)); @@ -622,7 +624,8 @@ int main(int argc, char *argv[]) die("ioctl SIOCSIFFLAGS"); if (i_am_unix98_pty_master) { /* get name of pts-device */ - if ((namepts = ptsname(fdpty)) == NULL) { + namepts = ptsname(fdpty); + if (namepts == NULL) { fprintf(stderr, "%s: Cannot get name of pts-device.\n", progname); exit (1); } @@ -673,7 +676,9 @@ int main(int argc, char *argv[]) printf("reopening master tty: %s\n", master_name); close(fdpty); - if ((fdpty = open(master_name, O_RDWR | O_NOCTTY | O_NONBLOCK)) < 0) { + fdpty = open(master_name, + O_RDWR | O_NOCTTY | O_NONBLOCK); + if (fdpty < 0) { fprintf(stderr, "%s: cannot reopen \"%s\"\n", progname, master_name); exit(1); -- cgit v1.2.3