git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: sizeof(struct ...)

From
René Scharfe <rene.scharfe@lsrfire.ath.cx>
Date
Nov 23, 2006, 17:57 UTC
Message-ID
<4565E0EC.4030709@lsrfire.ath.cx>
In-Reply-To
<4565CA02.20602@shadowen.org>
Andy Whitcroft schrieb:
> Perhaps we can look and see what a portable application like gzip or
> bzip2 do in this situation.  They must have the same problem.

Info-ZIP's zip uses structs only for in-memory storage and has a write function for each of them that writes the members one by one. I find the structs in archive-zip.c easier to read, but I might be biased. ;-)

Anyway, archive-zip.c assumes that there is no padding between unsigned char arrays and that an unsigned char is exactly one byte wide. The additional current assumption -- that sizeof(struct ...) sums up the sizes of all struct members -- is wrong on ARM, and the patches in this thread correct this error.

So we're not as portable as Info-ZIP, but I think the assumptions above hold true for all interesting architectures. And we have a readable description of the on-disk ZIP file headers.

Previous: Andy WhitcroftNext: Erik Mouw
Message 9 of 13 in “sizeof(struct ...)”
  1. Gerrit PapeNov 23, 2006
  2. René ScharfeNov 23, 2006
  3. René ScharfeNov 23, 2006
  4. Andy WhitcroftNov 23, 2006
  5. René ScharfeNov 23, 2006
  6. Erik MouwNov 23, 2006
  7. René ScharfeNov 23, 2006
  8. Andy WhitcroftNov 23, 2006
  9. René ScharfeNov 23, 2006
  10. Erik MouwNov 23, 2006
  11. Junio C HamanoNov 23, 2006
  12. archive-zip: don't use sizeof(struct ...)René Scharfe, Nov 23, 2006
  13. Gerrit PapeNov 24, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.