Browse Source

dpkg-query: Return a valid width even if opening /dev/tty failed

This was spotted by a run with the clang static analyzer.
Guillem Jover 15 years ago
parent
commit
aab72be3be
1 changed files with 6 additions and 3 deletions
  1. 6 3
      src/querycmd.c

+ 6 - 3
src/querycmd.c

@@ -65,12 +65,15 @@ static int getwidth(void) {
   else if (!isatty(1))
     return -1;
   else {
+    res = 80;
+
     if ((fd=open("/dev/tty",O_RDONLY))!=-1) {
-      if (ioctl(fd, TIOCGWINSZ, &ws)==-1)
-	ws.ws_col=80;
+      if (ioctl(fd, TIOCGWINSZ, &ws) == 0)
+        res = ws.ws_col;
       close(fd);
     }
-    return ws.ws_col;
+
+    return res;
   }
 }