summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRalf Baechle <ralf@linux-mips.org>2017-08-02 23:25:13 +0200
committerRalf Baechle <ralf@linux-mips.org>2017-08-03 04:21:23 +0200
commit6afad7276402a90b3776ddeefb205978af42fdab (patch)
tree595886e869c364e504eacc1d472c07ae51d7bb4a
parentca4de17280673efe76a95bf904d11e1fa75c62d4 (diff)
Delete more assignments in if conditions.
Based on below coccinelle script with a bad transformation fixed up manually. @if1@ expression E, F, G; binary operator X; statement S; @@ - if ((E = F) X G) + E = F; + if (E X G) S @if2@ expression E, F, G; binary operator X; statement S; @@ - if (G X (E = F)) + E = F; + if (E X G) S @if3@ expression E, F; statement S; @@ - if (!(E = F)) + E = F; + if (!E) S @if4@ expression E, F; statement S; @@ - if ((E = F)) + E = F; + if (E) S Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
-rw-r--r--ax25/access.c18
-rw-r--r--ax25/axgetput/proto_bin.c3
-rw-r--r--ax25/axgetput/util.c15
-rw-r--r--ax25/axspawn.c59
-rw-r--r--hdlcutil/smdiag.c21
5 files changed, 75 insertions, 41 deletions
diff --git a/ax25/access.c b/ax25/access.c
index 2ecbb1d..05d3375 100644
--- a/ax25/access.c
+++ b/ax25/access.c
@@ -210,7 +210,8 @@ static void write_example_passwd(char *pwfile, char pwlocation,
return;
fchown(i, (pwlocation == SYSTEMPW ? 0 : pw->pw_uid), (pwlocation == SYSTEMPW ? 0 : pw->pw_gid));
close(i);
- if ( ! (f = fopen(pwfile, "w")) )
+ f = fopen(pwfile, "w");
+ if (!f)
return;
fprintf(f, "# %s Password file for axspawn\n", (pwlocation == SYSTEMPW ? "System" : "User"));
if (pwlocation == SYSTEMPW) {
@@ -255,7 +256,8 @@ char *read_pwd (struct passwd *pw, int *pwtype)
}
if (!S_ISREG(statbuf.st_mode) || (statbuf.st_mode & (S_IROTH | S_IWOTH)))
continue;
- if ( !(f = fopen(pwfile, "r")) )
+ f = fopen(pwfile, "r");
+ if (!f)
continue;
} else {
if (only_systempw)
@@ -300,7 +302,8 @@ char *read_pwd (struct passwd *pw, int *pwtype)
write_ax25(buf, strlen(buf), 1);
/* go on.. if user takes no action, he always gets this message */
}
- if ( !(f = fopen(pwfile, "r")) )
+ f = fopen(pwfile, "r");
+ if (!f)
goto end;
}
@@ -321,7 +324,8 @@ char *read_pwd (struct passwd *pw, int *pwtype)
}
goto end;
}
- if ((p = strchr(buf, '\n')))
+ p = strchr(buf, '\n');
+ if (p)
*p = 0;
if (!*buf || isspace(*buf & 0xff))
continue;
@@ -332,7 +336,8 @@ char *read_pwd (struct passwd *pw, int *pwtype)
only_systempw = 1;
continue;
}
- if (!(p = strchr(buf, ':')))
+ p = strchr(buf, ':');
+ if (!p)
continue;
*p++ = 0;
if (strcmp(pw->pw_name, buf))
@@ -345,7 +350,8 @@ char *read_pwd (struct passwd *pw, int *pwtype)
if (!Strcasecmp(p_buf, "unix")) {
pass = p_buf;
} else {
- if (!(pass = strchr(p_buf, ':')))
+ pass = strchr(p_buf, ':');
+ if (!pass)
continue;
*pass++ = 0;
}
diff --git a/ax25/axgetput/proto_bin.c b/ax25/axgetput/proto_bin.c
index 69d12a4..7d5eb3a 100644
--- a/ax25/axgetput/proto_bin.c
+++ b/ax25/axgetput/proto_bin.c
@@ -484,7 +484,8 @@ int bget(void) {
}
if (fdin_is_pipe && !is_stream) {
sl = stored_file;
- if (!(stored_file = stored_file->next))
+ stored_file = stored_file->next;
+ if (!stored_file)
is_eof = 1;
free(sl);
}
diff --git a/ax25/axgetput/util.c b/ax25/axgetput/util.c
index a4a83c0..69adb60 100644
--- a/ax25/axgetput/util.c
+++ b/ax25/axgetput/util.c
@@ -116,19 +116,23 @@ char *get_fixed_filename(char *line, long size, unsigned int msg_crc, int genera
*filename = 0;
- if ((p = strchr(line, '\"'))) {
+ p = strchr(line, '\"');
+ if (p) {
p++;
}
/* security.. */
- if ((q = strrchr((p ? p : line), '/'))) {
+ q = strrchr((p ? p : line), '/');
+ if (q) {
p = ++q;
}
- if ((q = strrchr((p ? p : line), '\\'))) {
+ q = strrchr((p ? p : line), '\\');
+ if (q) {
p = ++q;
}
- if ((q = strrchr((p ? p : line), ':'))) {
+ q = strrchr((p ? p : line), ':');
+ if (q) {
p = ++q;
}
if (!p) {
@@ -144,7 +148,8 @@ char *get_fixed_filename(char *line, long size, unsigned int msg_crc, int genera
}
*r = 0;
strtrim(filename);
- if ((q = strrchr(filename, '.'))) {
+ q = strrchr(filename, '.');
+ if (q) {
if (!*(q+1)) {
/* remove trailing dots */
*q = 0;
diff --git a/ax25/axspawn.c b/ax25/axspawn.c
index 3308a70..dd234f0 100644
--- a/ax25/axspawn.c
+++ b/ax25/axspawn.c
@@ -741,10 +741,12 @@ static void kick_wqueue(int dummy)
/* recompute waitqueue */
if (wqueue_head->len < bufsize && wqueue_head->next) {
int s_len;
- if (!(s = malloc(bufsize))) {
+ s = malloc(bufsize);
+ if (!s) {
break;
}
- if (!(new_head = malloc(sizeof(struct write_queue)))) {
+ new_head = malloc(sizeof(struct write_queue));
+ if (!new_head) {
free(s);
break;
}
@@ -1273,8 +1275,9 @@ static void read_config(void)
{
fgets(buf, sizeof(buf), fp);
p = strchr(buf, '#');
- if (p || (p = strchr(buf, '\n')))
- *p='\0';
+ if (!p)
+ p = strchr(buf, '\n');
+ *p='\0';
if (buf[0] != '\0')
{
@@ -1438,7 +1441,8 @@ int main(int argc, char **argv)
if (gethostname(buf, sizeof(buf)) < 0) {
strcpy(prompt, "Check");
} else {
- if ((p = strchr(buf, '.')))
+ p = strchr(buf, '.');
+ if (p)
*p = 0;
strncpy(prompt, buf, sizeof(prompt));
prompt[sizeof(prompt)-1] = 0;
@@ -1618,7 +1622,8 @@ int main(int argc, char **argv)
}
again:
- if (!(pwd = read_pwd(pw, &pwtype))) {
+ pwd = read_pwd(pw, &pwtype);
+ if (!pwd) {
if ((!pwtype || pwtype != PW_CLEARTEXT) && (pwtype != PW_UNIX)) {
sleep (EXITDELAY);
return 1;
@@ -1644,7 +1649,8 @@ again:
return -11;
}
buf[cnt] = 0;
- if ((p = strchr(buf, '\n')))
+ p = strchr(buf, '\n');
+ if (p)
*p = 0;
if ((pwtype & PW_MD5) && !strcmp(buf, "sys") && (pwtype_orig & PW_SYS)) {
pwtype = (pwtype_orig & ~PW_MD5);
@@ -1766,11 +1772,14 @@ again:
chdir(p);
}
- if ((envp[envc] = malloc(strlen(p)+6)))
+ envp[envc] = malloc(strlen(p) + 6);
+ if (envp[envc])
sprintf(envp[envc++], "HOME=%s", p);
- if ((envp[envc] = malloc(strlen(pw->pw_name)+6)))
+ envp[envc] = malloc(strlen(pw->pw_name) + 6);
+ if (envp[envc])
sprintf(envp[envc++], "USER=%s", pw->pw_name);
- if ((envp[envc] = malloc(strlen(pw->pw_name)+9)))
+ envp[envc] = malloc(strlen(pw->pw_name) + 9);
+ if (envp[envc])
sprintf(envp[envc++], "LOGNAME=%s", pw->pw_name);
if (pw->pw_shell && *(pw->pw_shell)) {
@@ -1778,9 +1787,11 @@ again:
} else {
shell = "/bin/sh";
}
- if ((p = strrchr(shell, '/'))) {
+ p = strrchr(shell, '/');
+ if (p) {
if (p[1]) {
- if ((p = strdup(p)))
+ p = strdup(p);
+ if (p)
*p = '-';
} else p = NULL;
@@ -1788,14 +1799,16 @@ again:
if (!p)
p = shell;
chargv[chargc++] = p;
- if ((envp[envc] = malloc(strlen(shell)+7)))
+ envp[envc] = malloc(strlen(shell) + 7);
+ if (envp[envc])
sprintf(envp[envc++], "SHELL=%s", shell);
if (pw->pw_uid == 0)
p = "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin";
else
p = "/bin:/usr/bin:/usr/local/bin";
- if ((envp[envc] = malloc(strlen(p)+6)))
+ envp[envc] = malloc(strlen(p) + 6);
+ if (envp[envc])
sprintf(envp[envc++], "PATH=%s", p);
} else {
@@ -1831,18 +1844,24 @@ again:
}
chargv[chargc] = NULL;
- if ((envp[envc] = malloc(30)))
+ envp[envc] = malloc(30);
+ if (envp[envc])
sprintf(envp[envc++], "AXCALL=%s", call);
- if ((envp[envc] = malloc(30)))
+ envp[envc] = malloc(30);
+ if (envp[envc])
sprintf(envp[envc++], "CALL=%s", user);
- if ((envp[envc] = malloc(30)))
+ envp[envc] = malloc(30);
+ if (envp[envc])
sprintf(envp[envc++], "PROTOCOL=%s", protocol);
- if ((envp[envc] = malloc(30)))
+ envp[envc] = malloc(30);
+ if (envp[envc])
sprintf(envp[envc++], "TERM=dumb"); /* SuSE bug (dump - tsts) */
/* other useful defaults */
- if ((envp[envc] = malloc(30)))
+ envp[envc] = malloc(30);
+ if (envp[envc])
sprintf(envp[envc++], "EDITOR=/usr/bin/ex");
- if ((envp[envc] = malloc(30)))
+ envp[envc] = malloc(30);
+ if (envp[envc])
sprintf(envp[envc++], "LESS=-d -E -F");
envp[envc] = NULL;
diff --git a/hdlcutil/smdiag.c b/hdlcutil/smdiag.c
index 17ef026..14496c8 100644
--- a/hdlcutil/smdiag.c
+++ b/hdlcutil/smdiag.c
@@ -94,7 +94,8 @@ static int openwindow(char *disp, int constell, int samplesperbit)
XColor color, dummy;
XSizeHints sizehints;
- if (!(display = XOpenDisplay(NULL)))
+ display = XOpenDisplay(NULL);
+ if (!display)
return -1;
XSetErrorHandler(x_error_handler);
XAllocNamedColor(display, DefaultColormap(display, 0), "red",
@@ -103,16 +104,17 @@ static int openwindow(char *disp, int constell, int samplesperbit)
col_background = WhitePixel(display, 0);
col_trace = BlackPixel(display, 0);
attr.background_pixel = col_background;
- if (!(window = XCreateWindow(display, XRootWindow(display, 0),
- 200, 200, WIDTH, HEIGHT, 5,
- DefaultDepth(display, 0),
- InputOutput, DefaultVisual(display, 0),
- CWBackPixel, &attr))) {
+ window = XCreateWindow(display, XRootWindow(display, 0), 200, 200,
+ WIDTH, HEIGHT, 5, DefaultDepth(display, 0),
+ InputOutput, DefaultVisual(display, 0),
+ CWBackPixel, &attr);
+ if (!window) {
fprintf(stderr, "smdiag: unable to open X window\n");
exit(1);
}
- if (!(pixmap = XCreatePixmap(display, window, WIDTH, HEIGHT,
- DefaultDepth(display, 0)))) {
+ pixmap = XCreatePixmap(display, window, WIDTH, HEIGHT,
+ DefaultDepth(display, 0));
+ if (!pixmap) {
fprintf(stderr, "smdiag: unable to open offscreen pixmap\n");
exit(1);
}
@@ -389,7 +391,8 @@ int main(int argc, char *argv[])
} else
usleep(100000L);
if (display) {
- if ((cp = getkey())) {
+ cp = getkey();
+ if (cp) {
for (; *cp; cp++) {
printf("char pressed: '%c'\n", *cp);
switch (*cp) {