Browse Source

Avoid assignments in C conditionals

Guillem Jover 14 years ago
parent
commit
d33cf5c4aa
9 changed files with 34 additions and 16 deletions
  1. 4 2
      dpkg-deb/extract.c
  2. 2 1
      dpkg-split/queue.c
  3. 2 1
      dselect/pkglist.cc
  4. 2 1
      lib/dpkg/mlib.c
  5. 2 1
      lib/dpkg/options.c
  6. 2 1
      src/filesdb.c
  7. 2 1
      src/main.c
  8. 10 4
      src/querycmd.c
  9. 8 4
      src/statdb.c

+ 4 - 2
dpkg-deb/extract.c

@@ -366,7 +366,8 @@ controlextractvextract(int admin, enum dpkg_tar_options taroptions,
 {
   const char *debar, *dir;
 
-  if (!(debar= *argv++))
+  debar = *argv++;
+  if (debar == NULL)
     badusage(_("--%s needs a .deb filename argument"),cipaction->olong);
   dir = *argv++;
   if (!dir) {
@@ -387,7 +388,8 @@ do_fsystarfile(const char *const *argv)
 {
   const char *debar;
 
-  if (!(debar= *argv++))
+  debar = *argv++;
+  if (debar == NULL)
     badusage(_("--%s needs a .deb filename argument"),cipaction->olong);
   if (*argv)
     badusage(_("--%s takes only one argument (.deb filename)"),cipaction->olong);

+ 2 - 1
dpkg-split/queue.c

@@ -138,7 +138,8 @@ do_auto(const char *const *argv)
 
   if (!opt_outputfile)
     badusage(_("--auto requires the use of the --output option"));
-  if (!(partfile= *argv++) || *argv)
+  partfile = *argv++;
+  if (partfile == NULL || *argv)
     badusage(_("--auto requires exactly one part file argument"));
 
   refi= nfmalloc(sizeof(struct partqueue));

+ 2 - 1
dselect/pkglist.cc

@@ -523,7 +523,8 @@ packagelist::checksearch(char *rx)
    }
   }
 
-  if ((r=regcomp(&searchfsm, rx, opt))!=0) {
+  r = regcomp(&searchfsm, rx, opt);
+  if (r != 0) {
     displayerror(_("error in regular expression"));
     return false;
   }

+ 2 - 1
lib/dpkg/mlib.c

@@ -126,7 +126,8 @@ setcloexec(int fd, const char *fn)
 {
   int f;
 
-  if ((f=fcntl(fd, F_GETFD))==-1)
+  f = fcntl(fd, F_GETFD);
+  if (f == -1)
     ohshite(_("unable to read filedescriptor flags for %.250s"),fn);
   if (fcntl(fd, F_SETFD, (f|FD_CLOEXEC))==-1)
     ohshite(_("unable to set close-on-exec flag for %.250s"),fn);

+ 2 - 1
lib/dpkg/options.c

@@ -198,7 +198,8 @@ loadcfgfile(const char *prog, const struct cmdinfo *cmdinfos)
   myfileopt(file, cmdinfos);
   free(file);
 
-  if ((home = getenv("HOME")) != NULL) {
+  home = getenv("HOME");
+  if (home != NULL) {
     m_asprintf(&file, "%s/.%s.cfg", home, prog);
     myfileopt(file, cmdinfos);
     free(file);

+ 2 - 1
src/filesdb.c

@@ -304,7 +304,8 @@ ensure_packagefiles_available(struct pkginfo *pkg)
     while (thisline < loaded_list_end) {
       struct filenamenode *namenode;
 
-      if (!(ptr = memchr(thisline, '\n', loaded_list_end - thisline)))
+      ptr = memchr(thisline, '\n', loaded_list_end - thisline);
+      if (ptr == NULL)
         ohshit(_("files list file for package '%.250s' is missing final newline"),
                pkg_name(pkg, pnaw_nonambig));
       /* Where to start next time around. */

+ 2 - 1
src/main.c

@@ -735,7 +735,8 @@ commandfd(const char *const *argv)
   infd = strtol(pipein, &endptr, 10);
   if (pipein == endptr || *endptr || infd < 0 || infd > INT_MAX || errno != 0)
     ohshit(_("invalid integer for --%s: `%.250s'"), cipaction->olong, pipein);
-  if ((in= fdopen(infd, "r")) == NULL)
+  in = fdopen(infd, "r");
+  if (in == NULL)
     ohshite(_("couldn't open `%i' for stream"), (int) infd);
 
   for (;;) {

+ 10 - 4
src/querycmd.c

@@ -67,14 +67,20 @@ static int getwidth(void) {
   struct winsize ws;
   const char *columns;
 
-  if ((columns=getenv("COLUMNS")) && ((res=atoi(columns))>0))
-    return res;
-  else if (!isatty(1))
+  columns = getenv("COLUMNS");
+  if (columns) {
+    res = atoi(columns);
+    if (res > 0)
+      return res;
+  }
+
+  if (!isatty(1))
     return -1;
   else {
     res = 80;
 
-    if ((fd=open("/dev/tty",O_RDONLY))!=-1) {
+    fd = open("/dev/tty", O_RDONLY);
+    if (fd != -1) {
       if (ioctl(fd, TIOCGWINSZ, &ws) == 0)
         res = ws.ws_col;
       close(fd);

+ 8 - 4
src/statdb.c

@@ -167,7 +167,8 @@ ensure_statoverrides(void)
 	while (thisline < loaded_list_end) {
 		fso = nfmalloc(sizeof(struct file_stat));
 
-		if (!(ptr = memchr(thisline, '\n', loaded_list_end - thisline)))
+		ptr = memchr(thisline, '\n', loaded_list_end - thisline);
+		if (ptr == NULL)
 			ohshit(_("statoverride file is missing final newline"));
 		/* Where to start next time around. */
 		nextline = ptr + 1;
@@ -176,7 +177,8 @@ ensure_statoverrides(void)
 		*ptr = '\0';
 
 		/* Extract the uid. */
-		if (!(ptr = memchr(thisline, ' ', nextline - thisline)))
+		ptr = memchr(thisline, ' ', nextline - thisline);
+		if (ptr == NULL)
 			ohshit(_("syntax error in statoverride file"));
 		*ptr = '\0';
 
@@ -188,7 +190,8 @@ ensure_statoverrides(void)
 			ohshit(_("unexpected end of line in statoverride file"));
 
 		/* Extract the gid */
-		if (!(ptr = memchr(thisline, ' ', nextline - thisline)))
+		ptr = memchr(thisline, ' ', nextline - thisline);
+		if (ptr == NULL)
 			ohshit(_("syntax error in statoverride file"));
 		*ptr = '\0';
 
@@ -200,7 +203,8 @@ ensure_statoverrides(void)
 			ohshit(_("unexpected end of line in statoverride file"));
 
 		/* Extract the mode */
-		if (!(ptr = memchr(thisline, ' ', nextline - thisline)))
+		ptr = memchr(thisline, ' ', nextline - thisline);
+		if (ptr == NULL)
 			ohshit(_("syntax error in statoverride file"));
 		*ptr = '\0';