diff options
author | Ralf Baechle <ralf@linux-mips.org> | 2017-07-28 14:26:57 +0200 |
---|---|---|
committer | Ralf Baechle <ralf@linux-mips.org> | 2017-08-03 03:46:12 +0200 |
commit | d08f3360f435f17590416857a95fa9ccfe19204c (patch) | |
tree | 0a3434ba7d43bd3d4be7081377f147da400268f1 | |
parent | b541f5ddd8936a1f2fa69d1917d6812139da0c4e (diff) |
treewide: Kill assignments in if conditions.
Somewhat hard to read and the code base already has many overlong
lines
Found with below spatch files:
@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 <ralf@linux-mips.org>
-rw-r--r-- | ax25ipd/bpqether.c | 15 | ||||
-rw-r--r-- | ax25ipd/config.c | 6 | ||||
-rw-r--r-- | ax25ipd/io.c | 3 | ||||
-rw-r--r-- | ax25mond/ax25mond.c | 20 | ||||
-rw-r--r-- | ax25rtd/ax25rtd.c | 14 | ||||
-rw-r--r-- | ax25rtd/config.c | 24 | ||||
-rw-r--r-- | ax25rtd/listener.c | 3 | ||||
-rw-r--r-- | call/call.c | 76 | ||||
-rw-r--r-- | call/yapp.c | 60 | ||||
-rw-r--r-- | listen/listen.c | 14 |
10 files changed, 136 insertions, 99 deletions
diff --git a/ax25ipd/bpqether.c b/ax25ipd/bpqether.c index 0b0b57f..db02839 100644 --- a/ax25ipd/bpqether.c +++ b/ax25ipd/bpqether.c @@ -126,7 +126,8 @@ static int tun_alloc(char *dev) struct ifreq ifr; int fd, err; - if ((fd = open("/dev/net/tun", O_RDWR)) < 0) + fd = open("/dev/net/tun", O_RDWR); + if (fd < 0) return -1; memset(&ifr, 0, sizeof(ifr)); @@ -142,7 +143,8 @@ static int tun_alloc(char *dev) ifr.ifr_name[IFNAMSIZ-1] = 0; } - if ((err = ioctl(fd, TUNSETIFF, (void *) &ifr)) < 0 ) { + err = ioctl(fd, TUNSETIFF, (void *)&ifr); + if (err < 0) { close(fd); return err; } @@ -191,7 +193,8 @@ int open_ethertap(char *ifname) #ifdef TRY_TUNTAP } else { strcpy(devname, ifname); - if ((fd = tun_alloc(devname)) < 0) { + fd = tun_alloc(devname); + if (fd < 0) { LOGL2("%s: %s\n", devname, strerror(errno)); return -1; } @@ -201,7 +204,8 @@ int open_ethertap(char *ifname) } ethertap_header_len = (tuntap ? ETHERTAP_HEADER_LEN_TUN : ETHERTAP_HEADER_LEN_ETHERTAP); - if ((skfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { + skfd = socket(AF_INET, SOCK_DGRAM, 0); + if (skfd < 0) { perror("socket()"); close(fd); return -1; @@ -308,7 +312,8 @@ int set_bpq_dev_call_and_up(char *ifname) LOGL1("found bpq device %s for %s\n", bpq_name, dev_name); - if ((skfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { + skfd = socket(AF_INET, SOCK_DGRAM, 0); + if (skfd < 0) { perror("socket()"); return -1; } diff --git a/ax25ipd/config.c b/ax25ipd/config.c index e0db591..ecbd1c2 100644 --- a/ax25ipd/config.c +++ b/ax25ipd/config.c @@ -87,7 +87,8 @@ void config_read(char *f) else fname=f; - if ((cf = fopen(fname, "r")) == NULL) { + cf = fopen(fname, "r"); + if (cf == NULL) { fprintf(stderr, "Config file %s not found or could not be opened\n", fname); @@ -99,7 +100,8 @@ void config_read(char *f) while (fgets(buf, 255, cf) != NULL) { strcpy(cbuf, buf); lineno++; - if ((e = parse_line(buf)) < 0) { + e = parse_line(buf); + if (e < 0) { fprintf(stderr, "Config error at line %d: ", lineno); if (e == -1) diff --git a/ax25ipd/io.c b/ax25ipd/io.c index 56ef30f..c0db51d 100644 --- a/ax25ipd/io.c +++ b/ax25ipd/io.c @@ -323,7 +323,8 @@ void io_open(void) if (i_am_unix98_pty_master) { /* get name of pts-device */ - if ((namepts = ptsname(ttyfd)) == NULL) { + namepts = ptsname(ttyfd); + if (namepts == NULL) { perror("Cannot get name of pts-device."); exit(1); } diff --git a/ax25mond/ax25mond.c b/ax25mond/ax25mond.c index 5530bf5..bc1186c 100644 --- a/ax25mond/ax25mond.c +++ b/ax25mond/ax25mond.c @@ -109,13 +109,15 @@ static struct sockaddr *build_sockaddr(const char *name, int *addrlen) addr.si.sin_addr.s_addr = INADDR_ANY; } else if (!strcmp(host_name, "loopback")) { addr.si.sin_addr.s_addr = inet_addr("127.0.0.1"); - } else if ((addr.si.sin_addr.s_addr = inet_addr(host_name)) == -1) { - struct hostent *hp = gethostbyname(host_name); - endhostent(); - if (!hp) - return NULL; - addr.si.sin_addr.s_addr = - ((struct in_addr *) (hp->h_addr))->s_addr; + } else {addr.si.sin_addr.s_addr = inet_addr(host_name); + if (addr.si.sin_addr.s_addr == -1) { + struct hostent *hp = gethostbyname(host_name); + endhostent(); + if (!hp) + return NULL; + addr.si.sin_addr.s_addr = + ((struct in_addr *) (hp->h_addr))->s_addr; + } } if (isdigit(*serv_name & 0xff)) { @@ -157,8 +159,8 @@ static void add_socket(char *sockname, char monmode) else sock_filename[sock_num][0] = 0; - if ((sock_list[sock_num] = - socket(saddr->sa_family, SOCK_STREAM, 0)) < 0) { + sock_list[sock_num] = socket(saddr->sa_family, SOCK_STREAM, 0); + if (sock_list[sock_num] < 0) { fprintf(stderr, "WARNING: Error opening socket \"%s\": %s\n", sockname, strerror(errno)); diff --git a/ax25rtd/ax25rtd.c b/ax25rtd/ax25rtd.c index a40cffe..99630c4 100644 --- a/ax25rtd/ax25rtd.c +++ b/ax25rtd/ax25rtd.c @@ -144,12 +144,14 @@ int main(int argc, char **argv) if (fork()) return 0; - if ((s = socket(PF_PACKET, SOCK_PACKET, htons(ETH_P_AX25))) == -1) { + s = socket(PF_PACKET, SOCK_PACKET, htons(ETH_P_AX25)); + if (s == -1) { perror("AX.25 socket"); return 1; } - if ((cntrl_s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { + cntrl_s = socket(AF_UNIX, SOCK_STREAM, 0); + if (cntrl_s < 0) { perror("Control socket"); return 1; } @@ -215,10 +217,10 @@ int main(int argc, char **argv) } } } else if (FD_ISSET(cntrl_s, &read_fds)) { - if ((cntrl_fd = - accept(cntrl_s, - (struct sockaddr *) &cntrl_addr, - &cntrl_len)) < 0) { + cntrl_fd = accept(cntrl_s, + (struct sockaddr *)&cntrl_addr, + &cntrl_len); + if (cntrl_fd < 0) { perror("accept Control"); save_cache(); daemon_shutdown(1); diff --git a/ax25rtd/config.c b/ax25rtd/config.c index a483a15..a0d56b6 100644 --- a/ax25rtd/config.c +++ b/ax25rtd/config.c @@ -132,7 +132,8 @@ static ax25_address *get_mycall(char *port) { char *addr; - if ((addr = ax25_config_get_addr(port)) == NULL) + addr = ax25_config_get_addr(port); + if (addr == NULL) return NULL; return asc2ax(addr); @@ -146,7 +147,8 @@ static void load_ports(void) struct ifreq ifr, *ifrp; int k, fd; - if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { + fd = socket(AF_INET, SOCK_DGRAM, 0); + if (fd < 0) { fprintf(stderr, "Unable to open socket\n"); exit(1); } @@ -557,13 +559,17 @@ void interpret_command(int fd, char *buf) if (!strcmp(cmd, "add")) { if (arg == NULL) return; - if ((arg2 = get_next_arg(&p)) == NULL) + arg2 = get_next_arg(&p); + if (arg2 == NULL) return; - if ((dev = get_next_arg(&p)) == NULL) + dev = get_next_arg(&p); + if (dev == NULL) return; - if ((time = get_next_arg(&p)) == NULL) + time = get_next_arg(&p); + if (time == NULL) return; - if ((config = dev_get_config(dev)) == NULL) + config = dev_get_config(dev); + if (config == NULL) return; sscanf(time, "%lx", &stamp); @@ -588,10 +594,12 @@ void interpret_command(int fd, char *buf) } else if (!strcmp(arg, "ip")) { ip = asc2ip(arg2); - if ((arg2 = get_next_arg(&p)) == NULL) + arg2 = get_next_arg(&p); + if (arg2 == NULL) return; - if ((arg = get_next_arg(&p)) == NULL) + arg = get_next_arg(&p); + if (arg == NULL) return; if (*arg == 'x') diff --git a/ax25rtd/listener.c b/ax25rtd/listener.c index 8a4ecf9..9ecb3c6 100644 --- a/ax25rtd/listener.c +++ b/ax25rtd/listener.c @@ -395,7 +395,8 @@ void ax25_receive(int sock) socklen_t asize; asize = sizeof(sa); - if ((size = recvfrom(sock, buf, sizeof(buf), 0, &sa, &asize)) < 0) { + size = recvfrom(sock, buf, sizeof(buf), 0, &sa, &asize); + if (size < 0) { perror("recvfrom"); save_cache(); daemon_shutdown(1); diff --git a/call/call.c b/call/call.c index 4c49cd4..e0fc054 100644 --- a/call/call.c +++ b/call/call.c @@ -579,7 +579,8 @@ static int nr_convert_call(char *address, struct full_sockaddr_ax25 *addr) for (call = address; *call != '\0'; call++) *call = toupper(*call); - if ((fp = fopen(PROC_NR_NODES_FILE, "r")) == NULL) { + fp = fopen(PROC_NR_NODES_FILE, "r"); + if (fp == NULL) { fprintf(stderr, "call: NET/ROM not included in the kernel\n"); return -1; @@ -624,7 +625,8 @@ static int connect_to(char *address[]) "call: too few arguments for Rose\n"); return -1; } - if ((fd = socket(AF_ROSE, SOCK_SEQPACKET, 0)) < 0) { + fd = socket(AF_ROSE, SOCK_SEQPACKET, 0); + if (fd < 0) { perror("socket"); return -1; } @@ -636,7 +638,8 @@ static int connect_to(char *address[]) "call: too few arguments for NET/ROM\n"); return -1; } - if ((fd = socket(AF_NETROM, SOCK_SEQPACKET, 0)) < 0) { + fd = socket(AF_NETROM, SOCK_SEQPACKET, 0); + if (fd < 0) { perror("socket"); return -1; } @@ -651,7 +654,8 @@ static int connect_to(char *address[]) "call: too few arguments for AX.25\n"); return -1; } - if ((fd = socket(AF_AX25, SOCK_SEQPACKET, 0)) < 0) { + fd = socket(AF_AX25, SOCK_SEQPACKET, 0); + if (fd < 0) { perror("socket"); return -1; } @@ -1017,8 +1021,8 @@ static int start_ab_download(int mode, WINDOW ** swin, wint * wintab, dupdstatw(*swin, "Bytes to receive: ", TRUE); - if ((gp->dwn_file = - open(gp->file_name, O_RDWR | O_CREAT, 0666)) == -1) { + gp->dwn_file = open(gp->file_name, O_RDWR | O_CREAT, 0666); + if (gp->dwn_file == -1) { snprintf(s, sizeof(s), "Unable to open %s", gp->file_name); statline(mode, s); if (write(fd, "#ABORT#\r", 8) == -1) { @@ -1168,7 +1172,8 @@ static int start_screen(char *call[]) for (p = idString; *p; p++) if (islower(*p)) *p = toupper(*p); - if ((win = initscr()) == NULL) + win = initscr(); + if (win == NULL) return -1; attron(A_REVERSE); @@ -1509,7 +1514,8 @@ static int readoutg(t_win * win_out, wint * wintab, menuitem * top, char buf[], c = (wchar_t) ci; if (c == keyesc) { - if ((value = top_menu(wintab, top, 1)) == 0) { + value = top_menu(wintab, top, 1); + if (value == 0) { restorecursor(mode, win_out); return 0; } @@ -1854,9 +1860,9 @@ static int searche_key_words(char buf[], int *bytes, char *parms, int *parmsbyte t = -1; while (*pkey_words[command] != '\0') { - if ((t = - compstr(pkey_words[command], &buf[cnt], - *bytes - cnt)) != -1) + t = compstr(pkey_words[command], &buf[cnt], + *bytes - cnt); + if (t != -1) break; command++; } @@ -2090,7 +2096,8 @@ static int cmd_call(char *call[], int mode, int encoding) gp.dwn_cnt = 0; wintab.next = NULL; - if ((fd = connect_to(call)) == -1) + fd = connect_to(call); + if (fd == -1) return FALSE; interrupted = FALSE; @@ -2275,17 +2282,16 @@ static int cmd_call(char *call[], int mode, int encoding) break; case 2: { - if ((sevenplcnt = - sevenplname(mode, - &swin, - &wintab, - &downloadfile, - &logfile, - parms, - parmsbytes, - buf, - bytes)) != - -1) + sevenplcnt = sevenplname(mode, + &swin, + &wintab, + &downloadfile, + &logfile, + parms, + parmsbytes, + buf, + bytes); + if (sevenplcnt != -1) sevenplus = TRUE; } break; @@ -2371,14 +2377,12 @@ static int cmd_call(char *call[], int mode, int encoding) if (buf[2] != '\0' && buf[2] != '\n') { c = buf + 2; - if ((t = - strchr(c, - '\n')) != NULL) + t = strchr(c, '\n'); + if (t != NULL) *t = '\0'; } else { - if ((c = - getenv("SHELL")) == - NULL) + c = getenv("SHELL"); + if (c == NULL) c = "/bin/sh"; } @@ -2453,8 +2457,8 @@ static int cmd_call(char *call[], int mode, int encoding) restorecursor(mode, &win_out); continue; } - if ((t = - strchr(buf, '\n')) != NULL) + t = strchr(buf, '\n'); + if (t != NULL) *t = '\0'; t = buf + 2; while (*t != '\0' && isspace(*t)) @@ -2581,8 +2585,8 @@ static int cmd_call(char *call[], int mode, int encoding) continue; case 'O': case 'o': - if ((t = - strchr(buf, '\n')) != NULL) + t = strchr(buf, '\n'); + if (t != NULL) *t = '\0'; if (logfile != -1) { close(logfile); @@ -2873,7 +2877,8 @@ int main(int argc, char **argv) ax25mode = *optarg == 'e'; break; case 'p': - if ((paclen = atoi(optarg)) == 0) { + paclen = atoi(optarg); + if (paclen == 0) { fprintf(stderr, "call: option '-p' requires a numeric argument\n"); return 1; @@ -2920,7 +2925,8 @@ int main(int argc, char **argv) printf("call: %s\n", VERSION); return 0; case 'w': - if ((window = atoi(optarg)) == 0) { + window = atoi(optarg); + if (window == 0) { fprintf(stderr, "call: option '-w' requires a numeric argument\n"); return 1; diff --git a/call/yapp.c b/call/yapp.c index 355701f..3be80a8 100644 --- a/call/yapp.c +++ b/call/yapp.c @@ -136,7 +136,8 @@ static void Send_NR(char *reason) char buffer[257]; int length; - if ((length = strlen(reason)) > 255) + length = strlen(reason); + if (length > 255) length = 255; buffer[0] = NAK; @@ -181,7 +182,8 @@ static void Send_CN(char *reason) char buffer[257]; int length; - if ((length = strlen(reason)) > 255) + length = strlen(reason); + if (length > 255) length = 255; buffer[0] = CAN; @@ -292,7 +294,8 @@ static int yapp_download_data(int *filefd, unsigned char *buffer) if (buffer[0] == SOH) { /* Parse header: 3 fields == YAPP C */ unsigned char *hptr, *hfield[3]; - if ((length = buffer[1]) == 0) + length = buffer[1]; + if (length == 0) length = 256; hptr = buffer + 2; while (length > 0) { @@ -311,10 +314,10 @@ static int yapp_download_data(int *filefd, unsigned char *buffer) } if (*filefd == -1) { - if ((*filefd = - open((char *)hfield[0], - O_RDWR | O_APPEND | O_CREAT, - 0666)) == -1) { + *filefd = open((char *)hfield[0], + O_RDWR | O_APPEND | O_CREAT, + 0666); + if (*filefd == -1) { printf("\n[Unable to open %s]\n", hfield[0]); Send_NR("Invalid filename"); @@ -357,7 +360,8 @@ static int yapp_download_data(int *filefd, unsigned char *buffer) case STATE_RD: if (buffer[0] == STX) { - if ((length = buffer[1]) == 0) + length = buffer[1]; + if (length == 0) length = 256; total += length; sprintf(Message, "RcvData %5d bytes received", @@ -449,7 +453,8 @@ static void yapp_download(int filefd) } if (FD_ISSET(fd, &sock_read)) { - if ((length = read(fd, buffer + buflen, 511)) > 0) { + length = read(fd, buffer + buflen, 511); + if (length > 0) { buflen += length; do { @@ -471,8 +476,8 @@ static void yapp_download(int filefd) } break; default: - if ((length = - buffer[1]) == 0) + length = buffer[1]; + if (length == 0) length = 256; if (buffer[0] == STX) length += yappc; @@ -678,9 +683,8 @@ static void yapp_upload(int filefd, char *filename, long filelength) if (FD_ISSET(fd, &sock_write)) { /* Writable, only STATE_SD */ if (outlen > 0) { - if ((n = - write(fd, outbuffer + outbufptr, - outlen)) > 0) { + n = write(fd, outbuffer + outbufptr, outlen); + if (n > 0) { outbufptr += n; outlen -= n; total += n; @@ -715,7 +719,8 @@ static void yapp_upload(int filefd, char *filename, long filelength) } if (FD_ISSET(fd, &sock_read)) { - if ((length = read(fd, buffer + buflen, 511)) > 0) { + length = read(fd, buffer + buflen, 511); + if (length > 0) { buflen += length; do { @@ -737,8 +742,8 @@ static void yapp_upload(int filefd, char *filename, long filelength) } break; default: - if ((length = - buffer[1]) == 0) + length = buffer[1]; + if (length == 0) length = 256; if (buflen >= (length + 2)) { if (!yapp_upload_data(filefd, filename, filelength, buffer)) @@ -772,7 +777,8 @@ void cmd_yapp(char *buf, int bytes) switch (buf[0]) { case 'U': case 'u': - if ((t = strchr(buf, '\n')) != NULL) + t = strchr(buf, '\n'); + if (t != NULL) *t = '\0'; t = buf + 2; while (*t != '\0' && isspace(*t)) @@ -783,7 +789,8 @@ void cmd_yapp(char *buf, int bytes) Send_NR("No filename"); return; } - if ((filefd = open(t, O_RDONLY)) == -1) { + filefd = open(t, O_RDONLY); + if (filefd == -1) { printf("\n[Unable to open upload file]\n"); Send_NR("Invalid filename"); return; @@ -805,19 +812,20 @@ void cmd_yapp(char *buf, int bytes) case 'D': case 'd': - if ((t = strchr(buf, '\n')) != NULL) + t = strchr(buf, '\n'); + if (t != NULL) *t = '\0'; t = buf + 2; while (*t != '\0' && isspace(*t)) t++; if (*t == '\0') filefd = -1; - else if ((filefd = - open(t, O_RDWR | O_APPEND | O_CREAT, - 0666)) == -1) { - printf("\n[Unable to open %s]\n", buf + 2); - Send_NR("Invalid filename"); - return; + else {filefd = open(t, O_RDWR | O_APPEND | O_CREAT, 0666); + if (filefd == -1) { + printf("\n[Unable to open %s]\n", buf + 2); + Send_NR("Invalid filename"); + return; + } } printf("\n[Downloading using YAPP]\n"); yapp_download(filefd); diff --git a/listen/listen.c b/listen/listen.c index af4f19d..bf60708 100644 --- a/listen/listen.c +++ b/listen/listen.c @@ -36,7 +36,8 @@ static void display_port(char *dev) { char *port; - if ((port = ax25_config_get_name(dev)) == NULL) + port = ax25_config_get_name(dev); + if (port == NULL) port = dev; lprintf(T_PORT, "%s: ", port); @@ -262,14 +263,16 @@ int main(int argc, char **argv) fprintf(stderr, "listen: no AX.25 port data configured\n"); if (port != NULL) { - if ((dev = ax25_config_get_dev(port)) == NULL) { + dev = ax25_config_get_dev(port); + if (dev == NULL) { fprintf(stderr, "listen: invalid port name - %s\n", port); return 1; } } - if ((sock = socket(PF_PACKET, SOCK_PACKET, htons(proto))) == -1) { + sock = socket(PF_PACKET, SOCK_PACKET, htons(proto)); + if (sock == -1) { perror("socket"); return 1; } @@ -287,9 +290,8 @@ int main(int argc, char **argv) signal(SIGINT, handle_sigint); signal(SIGTERM, handle_sigint); - if ((size = - recvfrom(sock, buffer, sizeof(buffer), 0, &sa, - &asize)) == -1) { + size = recvfrom(sock, buffer, sizeof(buffer), 0, &sa, &asize); + if (size == -1) { /* * Signals are cared for by the handler, and we * don't want to abort on SIGWINCH |