dovecot-2.2: lib: data-stack - fix pointer arithmetic compiler w...
dovecot at dovecot.org
dovecot at dovecot.org
Tue Jan 20 23:43:31 UTC 2015
details: http://hg.dovecot.org/dovecot-2.2/rev/3ef7f3d53d17
changeset: 18189:3ef7f3d53d17
user: Phil Carmody <phil at dovecot.fi>
date: Wed Jan 21 01:42:01 2015 +0200
description:
lib: data-stack - fix pointer arithmetic compiler warning
Clang's -fsanitize=unsigned-integer-overflow barfs as follows:
data-stack.c:477:29: runtime error: negation of 8 cannot be represented in type 'unsigned long'
data-stack.c:495:15: runtime error: negation of 8 cannot be represented in type 'unsigned long'
Which is of course complete bollocks. There is no 8, there's only an 8ul, and
the negation of 8ul is 0xfffffff8ul (or a wider equivalent). That's the law.
However, the pointer arithmetic which follows the negation, whilst almost
certainly working in practice, is probably bogus, so just make the thing
signed before the negation, and both problems go away.
Reported-by: Teemu Huovila <teemu.huovila at dovecot.fi>
Signed-off-by: Phil Carmody <phil at dovecot.fi>
diffstat:
src/lib/data-stack.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diffs (21 lines):
diff -r e9a8fc0e21c9 -r 3ef7f3d53d17 src/lib/data-stack.c
--- a/src/lib/data-stack.c Wed Jan 21 00:19:17 2015 +0200
+++ b/src/lib/data-stack.c Wed Jan 21 01:42:01 2015 +0200
@@ -474,7 +474,7 @@
alloc_growth = (new_alloc_size - last_alloc_size);
#ifdef DEBUG
size_t old_raw_size; /* sorry, non-C99 users - add braces if you need them */
- old_raw_size = *(size_t *)PTR_OFFSET(mem, -MEM_ALIGN(sizeof(size_t)));
+ old_raw_size = *(size_t *)PTR_OFFSET(mem, -(ptrdiff_t)MEM_ALIGN(sizeof(size_t)));
i_assert(ALLOC_SIZE(old_raw_size) == last_alloc_size);
/* Only check one byte for over-run, that catches most
offenders who are likely to use t_try_realloc() */
@@ -492,7 +492,7 @@
/* All reallocs are permanent by definition
However, they don't count as a new allocation */
current_frame_block->alloc_bytes[frame_pos] += alloc_growth;
- *(size_t *)PTR_OFFSET(mem, -MEM_ALIGN(sizeof(size_t))) = size;
+ *(size_t *)PTR_OFFSET(mem, -(ptrdiff_t)MEM_ALIGN(sizeof(size_t))) = size;
memset(PTR_OFFSET(mem, size), CLEAR_CHR,
new_alloc_size - size - MEM_ALIGN(sizeof(size_t)));
#endif
More information about the dovecot-cvs
mailing list