diff options
author | Nick Mathewson <nickm@torproject.org> | 2008-07-31 12:18:14 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2008-07-31 12:18:14 +0000 |
commit | 1a76cd179a7f8db9656ac0d74438b63f8c6bc529 (patch) | |
tree | dd8ea69346a86d02063fc4bccf3933083976cb21 /src/or | |
parent | 626fafe56390e357a00cd118a57eaf96a2ed45d8 (diff) | |
download | tor-1a76cd179a7f8db9656ac0d74438b63f8c6bc529.tar tor-1a76cd179a7f8db9656ac0d74438b63f8c6bc529.tar.gz |
When a struct ends with char a[1], the size of all earlier members of the struct is _not_ sizeof(st)-1; compilers add alignment. Problem spotted by rovv. Backport candidate.
svn:r16302
Diffstat (limited to 'src/or')
-rw-r--r-- | src/or/buffers.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/or/buffers.c b/src/or/buffers.c index 17bd85eea..d013ce2ff 100644 --- a/src/or/buffers.c +++ b/src/or/buffers.c @@ -69,12 +69,14 @@ typedef struct chunk_t { * more than one byte long. */ } chunk_t; +#define CHUNK_HEADER_LEN STRUCT_OFFSET(chunk_t, mem[0]) + /** Return the number of bytes needed to allocate a chunk to hold * <b>memlen</b> bytes. */ -#define CHUNK_ALLOC_SIZE(memlen) (sizeof(chunk_t) + (memlen) - 1) +#define CHUNK_ALLOC_SIZE(memlen) (CHUNK_HEADER_LEN + (memlen)) /** Return the number of usable bytes in a chunk allocated with * malloc(<b>memlen</b>). */ -#define CHUNK_SIZE_WITH_ALLOC(memlen) ((memlen) - sizeof(chunk_t) + 1) +#define CHUNK_SIZE_WITH_ALLOC(memlen) ((memlen) - CHUNK_HEADER_LEN) /** Return the next character in <b>chunk</b> onto which data can be appended. * If the chunk is full, this might be off the end of chunk->mem. */ |