changeset 9630:2558f66e22b5 draft

(svn r13693) -Fix (r11106, r11117): Do not rely on .tar files always ending with a block of zeros.
author frosch <frosch@openttd.org>
date Sat, 12 Jul 2008 14:49:43 +0000
parents b7aa76561a6c
children 45483fcc3a28
files src/fileio.cpp
diffstat 1 files changed, 4 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/fileio.cpp
+++ b/src/fileio.cpp
@@ -487,8 +487,10 @@
 	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) {