From bf9232fb613b33f178e8409be42290977f243255 Mon Sep 17 00:00:00 2001 From: Daniel Borkmann Date: Sat, 13 Jul 2013 16:16:17 +0200 Subject: trafgen: setup_shared_var: fix couple of things 1) Fix a couple of sparse warnings: trafgen.c:382:27: error: cannot size expression trafgen.c:391:33: error: cannot size expression trafgen.c:393:33: error: cannot size expression trafgen.c:401:25: error: cannot size expression 2) Use MAP_FAILED instead of (void *) -1 3) No need to cast to void * on mmap(2) 4) Use NULL instead of 0 as mmap(2)'s first argument Signed-off-by: Daniel Borkmann --- trafgen.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/trafgen.c b/trafgen.c index 3457bfd..726959b 100644 --- a/trafgen.c +++ b/trafgen.c @@ -376,10 +376,11 @@ static void apply_csum16(int csum_id) static struct cpu_stats *setup_shared_var(unsigned long cpus) { int fd; - char zbuff[cpus * sizeof(struct cpu_stats)], file[256]; + size_t len = cpus * sizeof(struct cpu_stats); + char zbuff[len], file[256]; struct cpu_stats *buff; - fmemset(zbuff, 0, sizeof(zbuff)); + fmemset(zbuff, 0, len); slprintf(file, sizeof(file), ".tmp_mmap.%u", (unsigned int) rand()); fd = creat(file, S_IRUSR | S_IWUSR); @@ -390,9 +391,9 @@ static struct cpu_stats *setup_shared_var(unsigned long cpus) S_IRUSR | S_IWUSR); write_or_die(fd, zbuff, sizeof(zbuff)); - buff = (void *) mmap(0, sizeof(zbuff), PROT_READ | PROT_WRITE, - MAP_SHARED, fd, 0); - if (buff == (void *) -1) + buff = mmap(NULL, sizeof(zbuff), PROT_READ | PROT_WRITE, + MAP_SHARED, fd, 0); + if (buff == MAP_FAILED) panic("Cannot setup shared variable!\n"); close(fd); -- cgit v1.2.3-54-g00ecf