diff options
author | Paul Menzel <paulepanter@users.sourceforge.net> | 2016-02-23 18:59:04 +0100 |
---|---|---|
committer | Martin Roth <martinroth@google.com> | 2016-02-24 19:26:49 +0100 |
commit | 87fe2360c4b8b1f3f475e1669e48c7c2ae7b242a (patch) | |
tree | 4eb34f367f40a288ac6237aa244cde9f2b04515a | |
parent | abf7d4d7e87a4cdb7d8fb957ab1dfd367707a406 (diff) | |
download | coreboot-87fe2360c4b8b1f3f475e1669e48c7c2ae7b242a.tar.xz |
commonlib/lz4_wrapper: Use correct casts to ensure valid calculations
Commit 09f2921b (cbfs: Add LZ4 in-place decompression support for
pre-RAM stages) breaks building cbfstool with gcc (Debian 4.9.2-10)
4.9.2 in Debian 8.3 (jessie) with a 32-bit user space. It works fine
in a 64-bit user space.
```
/home/joey/src/coreboot/src/commonlib/lz4_wrapper.c:164:18: note: in expansion of macro 'MIN'
size_t size = MIN((uint32_t)b.size, dst + dstn - out);
^
/home/joey/src/coreboot/src/commonlib/include/commonlib/helpers.h:29:35: error: signed and unsigned type in conditional expression [-Werror=sign-compare]
#define MIN(a,b) ((a) < (b) ? (a) : (b))
^
```
The problem is arithmetic on void*, so explicitly cast to the wanted
types as suggested by user *redi* in #gcc@irc.freenode.net.
Change-Id: I85bee25a69c432ef8bb934add7fd2e2e31f03662
Signed-off-by: Paul Menzel <paulepanter@users.sourceforge.net>
Reviewed-on: https://review.coreboot.org/13771
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Tested-by: build bot (Jenkins)
-rw-r--r-- | src/commonlib/lz4_wrapper.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/commonlib/lz4_wrapper.c b/src/commonlib/lz4_wrapper.c index ea7b90d8fd..1a765af06d 100644 --- a/src/commonlib/lz4_wrapper.c +++ b/src/commonlib/lz4_wrapper.c @@ -161,7 +161,7 @@ size_t ulz4fn(const void *src, size_t srcn, void *dst, size_t dstn) } if (b.not_compressed) { - size_t size = MIN((uint32_t)b.size, dst + dstn - out); + size_t size = MIN((uintptr_t)b.size, (uintptr_t)dst + dstn - (uintptr_t)out); memcpy(out, in, size); if (size < b.size) break; /* output overrun */ |