Sfoglia il codice sorgente

Do nothing in FileFd::Write() if Size is 0

Turn the do-while loop into while loops, so it simply does nothing
if the Size is already 0.

This reverts commit c0b271edc2f6d9e5dea5ac82fbc911f0e3adfa7a which
introduced a fix for a specific instance of the issue in the
CopyFile() function.

Closes: #808381
Julian Andres Klode 10 anni fa
parent
commit
5df91bc70a
1 ha cambiato i file con 5 aggiunte e 7 eliminazioni
  1. 5 7
      apt-pkg/contrib/fileutl.cc

+ 5 - 7
apt-pkg/contrib/fileutl.cc

@@ -165,7 +165,7 @@ bool CopyFile(FileFd &From,FileFd &To)
    unsigned long long ToRead = 0;
    unsigned long long ToRead = 0;
    do {
    do {
       if (From.Read(Buf.get(),BufSize, &ToRead) == false ||
       if (From.Read(Buf.get(),BufSize, &ToRead) == false ||
-	  (ToRead > 0 && To.Write(Buf.get(),ToRead) == false))
+	  To.Write(Buf.get(),ToRead) == false)
 	 return false;
 	 return false;
    } while (ToRead != 0);
    } while (ToRead != 0);
 
 
@@ -1654,9 +1654,9 @@ char* FileFd::ReadLine(char *To, unsigned long long const Size)
 /* */
 /* */
 bool FileFd::Write(const void *From,unsigned long long Size)
 bool FileFd::Write(const void *From,unsigned long long Size)
 {
 {
-   ssize_t Res;
+   ssize_t Res = 1;
    errno = 0;
    errno = 0;
-   do
+   while (Res > 0 && Size > 0)
    {
    {
       if (false)
       if (false)
 	 /* dummy so that the rest can be 'else if's */;
 	 /* dummy so that the rest can be 'else if's */;
@@ -1725,7 +1725,6 @@ bool FileFd::Write(const void *From,unsigned long long Size)
       if (d != NULL)
       if (d != NULL)
 	 d->seekpos += Res;
 	 d->seekpos += Res;
    }
    }
-   while (Res > 0 && Size > 0);
    
    
    if (Size == 0)
    if (Size == 0)
       return true;
       return true;
@@ -1734,9 +1733,9 @@ bool FileFd::Write(const void *From,unsigned long long Size)
 }
 }
 bool FileFd::Write(int Fd, const void *From, unsigned long long Size)
 bool FileFd::Write(int Fd, const void *From, unsigned long long Size)
 {
 {
-   ssize_t Res;
+   ssize_t Res = 1;
    errno = 0;
    errno = 0;
-   do
+   while (Res > 0 && Size > 0)
    {
    {
       Res = write(Fd,From,Size);
       Res = write(Fd,From,Size);
       if (Res < 0 && errno == EINTR)
       if (Res < 0 && errno == EINTR)
@@ -1747,7 +1746,6 @@ bool FileFd::Write(int Fd, const void *From, unsigned long long Size)
       From = (char const *)From + Res;
       From = (char const *)From + Res;
       Size -= Res;
       Size -= Res;
    }
    }
-   while (Res > 0 && Size > 0);
 
 
    if (Size == 0)
    if (Size == 0)
       return true;
       return true;