ACK: [PATCH 4/5] lib: fwts_mmap: avoid using void * pointer arithmetic

Alex Hung alex.hung at canonical.com
Tue Sep 16 02:15:13 UTC 2014


On 14-09-11 10:05 PM, Colin King 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;

Acked-by: Alex Hung <alex.hung at canonical.com>



More information about the fwts-devel mailing list