]> git.saurik.com Git - apt.git/commitdiff
simplify code to make compilers happy
authorDavid Kalnischkies <david@kalnischkies.de>
Thu, 6 Feb 2014 20:46:29 +0000 (21:46 +0100)
committerDavid Kalnischkies <david@kalnischkies.de>
Mon, 10 Feb 2014 17:07:50 +0000 (18:07 +0100)
Does the same as before, but is a bit simpler on the logic for humans as
well as compilers. scan-build complained about it at least with:
"Result of operation is garbage or undefined"

Reported-By: scan-build
apt-pkg/contrib/fileutl.cc

index 37155b688173c2c25bc92f043867da53caf1a3e1..71ac9c73f5d6b4d535c79e2db5380c386b674221 100644 (file)
@@ -1594,11 +1594,17 @@ unsigned long long FileFd::Tell()
 unsigned long long FileFd::FileSize()
 {
    struct stat Buf;
-   if ((d == NULL || d->pipe == false) && fstat(iFd,&Buf) != 0)
-      return FileFdErrno("fstat","Unable to determine the file size");
+
+   bool ispipe = (d != NULL && d->pipe == true);
+   if (ispipe == false)
+   {
+      if (fstat(iFd,&Buf) != 0)
+        return FileFdErrno("fstat","Unable to determine the file size");
+      ispipe = S_ISFIFO(Buf.st_mode);
+   }
 
    // for compressor pipes st_size is undefined and at 'best' zero
-   if ((d != NULL && d->pipe == true) || S_ISFIFO(Buf.st_mode))
+   if (ispipe == true)
    {
       // we set it here, too, as we get the info here for free
       // in theory the Open-methods should take care of it already