APPLIED: [PATCH 4/5] lib: fwts_mmap: avoid using void * pointer arithmetic
Keng-Yu Lin
keng-yu.lin at canonical.com
Tue Sep 16 05:43:15 UTC 2014
On Thu, Sep 11, 2014 at 10:05 PM, Colin King <colin.king at canonical.com> wrote:
> From: Colin Ian King <colin.king at canonical.com>
>
> cppcheck reports:
> When using void pointers in calculations, the behaviour is undefined
>
> Signed-off-by: Colin Ian King <colin.king at canonical.com>
> ---
> src/lib/src/fwts_mmap.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/src/lib/src/fwts_mmap.c b/src/lib/src/fwts_mmap.c
> index e92ee7e..fc88f5a 100644
> --- a/src/lib/src/fwts_mmap.c
> +++ b/src/lib/src/fwts_mmap.c
> @@ -17,6 +17,7 @@
> *
> */
> #include <unistd.h>
> +#include <stdint.h>
> #include <sys/mman.h>
> #include <sys/types.h>
> #include <sys/stat.h>
> @@ -63,7 +64,7 @@ void *fwts_mmap(const off_t start, const size_t size)
> return ret;
>
> if ((mem = mmap(NULL, length, PROT_READ, MAP_PRIVATE, fd, start - offset)) != MAP_FAILED)
> - ret = (mem + offset);
> + ret = (void *)((uint8_t *)mem + offset);
>
> close(fd);
>
> @@ -82,7 +83,7 @@ int fwts_munmap(void *mem, const size_t size)
> page_size = fwts_page_size();
> offset = ((off_t)(mem)) & (page_size - 1);
>
> - if (munmap(mem - offset, size + offset) < 0)
> + if (munmap((void *)((uint8_t *)mem - offset), size + offset) < 0)
> return FWTS_ERROR;
>
> return FWTS_OK;
> --
> 2.1.0
>
>
> --
> fwts-devel mailing list
> fwts-devel at lists.ubuntu.com
> Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/fwts-devel
More information about the fwts-devel
mailing list