diff options
author | Julian Andres Klode <jak@debian.org> | 2015-12-19 13:01:14 +0100 |
---|---|---|
committer | Julian Andres Klode <jak@debian.org> | 2015-12-19 13:02:50 +0100 |
commit | 5df91bc70aeac9f39f33d748a3b5602fbf2a3e81 (patch) | |
tree | 08662fadce968576b8b2a4cdcfc1fa335f02dcd3 | |
parent | c0b271edc2f6d9e5dea5ac82fbc911f0e3adfa7a (diff) |
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
-rw-r--r-- | apt-pkg/contrib/fileutl.cc | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index 1ffa407bc..0d1c272ab 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -165,7 +165,7 @@ bool CopyFile(FileFd &From,FileFd &To) unsigned long long ToRead = 0; do { if (From.Read(Buf.get(),BufSize, &ToRead) == false || - (ToRead > 0 && To.Write(Buf.get(),ToRead) == false)) + To.Write(Buf.get(),ToRead) == false) return false; } 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) { - ssize_t Res; + ssize_t Res = 1; errno = 0; - do + while (Res > 0 && Size > 0) { if (false) /* 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) d->seekpos += Res; } - while (Res > 0 && Size > 0); if (Size == 0) 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) { - ssize_t Res; + ssize_t Res = 1; errno = 0; - do + while (Res > 0 && Size > 0) { Res = write(Fd,From,Size); 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; Size -= Res; } - while (Res > 0 && Size > 0); if (Size == 0) return true; |