diff options
author | Daniel Borkmann <dborkman@redhat.com> | 2013-07-13 16:16:17 +0200 |
---|---|---|
committer | Daniel Borkmann <dborkman@redhat.com> | 2013-07-13 16:20:17 +0200 |
commit | bf9232fb613b33f178e8409be42290977f243255 (patch) | |
tree | e3f97b4a1bf6a655359e1f297e6f33c83de5a931 | |
parent | e513602eb85a742924abe5b60b5140a87ca86acb (diff) |
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 <dborkman@redhat.com>
-rw-r--r-- | trafgen.c | 11 |
1 files changed, 6 insertions, 5 deletions
@@ -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); |