summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2008-07-12 14:49:43 +0000
committerfrosch <frosch@openttd.org>2008-07-12 14:49:43 +0000
commit2b6dee7f64b81785d4e5ec16d1dddfa74a562a57 (patch)
tree5421cccd61f97f93468476bb34e9be6955a373fc /src
parent56379fff5192b3dfb1d70b77800930a9bd6ecff5 (diff)
downloadopenttd-2b6dee7f64b81785d4e5ec16d1dddfa74a562a57.tar.xz
(svn r13693) -Fix (r11106, r11117): Do not rely on .tar files always ending with a block of zeros.
Diffstat (limited to 'src')
-rw-r--r--src/fileio.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/fileio.cpp b/src/fileio.cpp
index 56528469a..09636640c 100644
--- a/src/fileio.cpp
+++ b/src/fileio.cpp
@@ -487,8 +487,10 @@ static bool TarListAddFile(const char *filename)
char empty[512];
memset(&empty[0], 0, sizeof(empty));
- while (!feof(f)) {
- pos += fread(&th, 1, 512, f);
+ for (;;) { // Note: feof() always returns 'false' after 'fseek()'. Cool, isn't it?
+ size_t num_bytes_read = fread(&th, 1, 512, f);
+ if (num_bytes_read != 512) break;
+ pos += num_bytes_read;
/* Check if we have the new tar-format (ustar) or the old one (a lot of zeros after 'link' field) */
if (strncmp(th.magic, "ustar", 5) != 0 && memcmp(&th.magic, &empty[0], 512 - offsetof(TarHeader, magic)) != 0) {