git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* sizeof(struct ...)
@ 2006-11-23 10:16 Gerrit Pape
  2006-11-23 12:43 ` René Scharfe
  0 siblings, 1 reply; 13+ messages in thread
From: Gerrit Pape @ 2006-11-23 10:16 UTC (permalink / raw)
  To: git

Hi, I don't think we can rely on sizeof(struct ...) to be the exact size
of the struct as defined.  As the selftests show, archive-zip doesn't
work correctly on Debian/arm

 http://buildd.debian.org/fetch.cgi?&pkg=git-core&ver=1%3A1.4.4-1&arch=arm&stamp=1164122355&file=log

It's because sizeof(struct zip_local_header) is 32, zip_dir_header 48,
and zip_dir_trailer 24, breaking the zip files.  Compiling with
-fpack-struct seemed to break other things, so I for now I ended up with
this (not so nice) workaround.

Regards, Gerrit.


diff --git a/archive-zip.c b/archive-zip.c
index ae5572a..4fcda44 100644
--- a/archive-zip.c
+++ b/archive-zip.c
@@ -211,7 +211,7 @@ static int write_zip_entry(const unsigne
 	}
 
 	/* make sure we have enough free space in the dictionary */
-	direntsize = sizeof(struct zip_dir_header) + pathlen;
+	direntsize = 46 + pathlen;
 	while (zip_dir_size < zip_dir_offset + direntsize) {
 		zip_dir_size += ZIP_DIRECTORY_MIN_SIZE;
 		zip_dir = xrealloc(zip_dir, zip_dir_size);
@@ -234,8 +234,8 @@ static int write_zip_entry(const unsigne
 	copy_le16(dirent.attr1, 0);
 	copy_le32(dirent.attr2, attr2);
 	copy_le32(dirent.offset, zip_offset);
-	memcpy(zip_dir + zip_dir_offset, &dirent, sizeof(struct zip_dir_header));
-	zip_dir_offset += sizeof(struct zip_dir_header);
+	memcpy(zip_dir + zip_dir_offset, &dirent, 46);
+	zip_dir_offset += 46;
 	memcpy(zip_dir + zip_dir_offset, path, pathlen);
 	zip_dir_offset += pathlen;
 	zip_dir_entries++;
@@ -251,8 +251,8 @@ static int write_zip_entry(const unsigne
 	copy_le32(header.size, uncompressed_size);
 	copy_le16(header.filename_length, pathlen);
 	copy_le16(header.extra_length, 0);
-	write_or_die(1, &header, sizeof(struct zip_local_header));
-	zip_offset += sizeof(struct zip_local_header);
+	write_or_die(1, &header, 30);
+	zip_offset += 30;
 	write_or_die(1, path, pathlen);
 	zip_offset += pathlen;
 	if (compressed_size > 0) {
@@ -282,7 +282,7 @@ static void write_zip_trailer(const unsi
 	copy_le16(trailer.comment_length, sha1 ? 40 : 0);
 
 	write_or_die(1, zip_dir, zip_dir_offset);
-	write_or_die(1, &trailer, sizeof(struct zip_dir_trailer));
+	write_or_die(1, &trailer, 22);
 	if (sha1)
 		write_or_die(1, sha1_to_hex(sha1), 40);

^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2006-11-24  8:53 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-11-23 10:16 sizeof(struct ...) Gerrit Pape
2006-11-23 12:43 ` René Scharfe
2006-11-23 13:38   ` René Scharfe
2006-11-23 13:55     ` Andy Whitcroft
2006-11-23 15:45       ` René Scharfe
2006-11-23 15:54         ` Erik Mouw
2006-11-23 16:14           ` René Scharfe
2006-11-23 16:19             ` Andy Whitcroft
2006-11-23 17:57               ` René Scharfe
2006-11-23 16:42             ` Erik Mouw
2006-11-23 20:47   ` Junio C Hamano
2006-11-23 22:02     ` [PATCH] archive-zip: don't use " René Scharfe
2006-11-24  8:53       ` Gerrit Pape

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).