summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2008-08-06 16:22:32 +0000
committerNick Mathewson <nickm@torproject.org>2008-08-06 16:22:32 +0000
commitc5ef95b8028703132184eaa67b77a541971e3b8a (patch)
tree81059642f6eb6cece6f4dc3f442715d490f39f6b
parenta062b6d306f15faf3ae4afb5037c015a9c158266 (diff)
downloadtor-c5ef95b8028703132184eaa67b77a541971e3b8a.tar.gz
tor-c5ef95b8028703132184eaa67b77a541971e3b8a.zip
r17505@tombo: nickm | 2008-07-31 08:24:58 -0400
backport buffer chunk size fix svn:r16448
-rw-r--r--ChangeLog6
-rw-r--r--src/or/buffers.c6
2 files changed, 10 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 33fc21f0be..1c12fbe97e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Changes in version 0.2.0.31 - 2008-08-??
+ o Minor bugfixes:
+ - Fix a small alignment and memory-wasting bug on buffer chunks. Spotted
+ by rovv.
+
+
Changes in version 0.2.0.30 - 2008-07-15
o Minor bugfixes:
- Stop using __attribute__((nonnull)) with GCC: it can give us useful
diff --git a/src/or/buffers.c b/src/or/buffers.c
index 99e8b0a3ab..eb1be863a9 100644
--- a/src/or/buffers.c
+++ b/src/or/buffers.c
@@ -63,12 +63,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. */