iolog: fix error when compiled as c++
authorCasey Bodley <cbodley@redhat.com>
Wed, 4 Nov 2015 16:03:11 +0000 (11:03 -0500)
committerCasey Bodley <cbodley@redhat.com>
Mon, 16 Nov 2015 14:36:32 +0000 (09:36 -0500)
Given the main.cc source file:
  #include <fio.h>
  int main() { return 0; }

And the gcc command line:
  gcc main.cc -Ifio

In file included from fio/stat.h:4:0,
                 from fio/thread_options.h:7,
                 from fio/fio.h:18,
                 from main.cc:1:
fio/iolog.h: In function 'io_sample* __get_sample(void*, int,
uint64_t)':
fio/iolog.h:125:53: warning: pointer of type 'void *' used in arithmetic
[-Wpointer-arith]
  return samples + sample * __log_entry_sz(log_offset);
                                                     ^
fio/iolog.h:125:17: error: invalid conversion from 'void*' to
'io_sample*' [-fpermissive]
  return samples + sample * __log_entry_sz(log_offset);

Signed-off-by: Casey Bodley <cbodley@redhat.com>
iolog.h

diff --git a/iolog.h b/iolog.h
index b1c13bf7e16b7230c11a9c9dd3c459236a5bef05..aa4562d489b3bb944577bcb3ec599f9703e0ead4 100644 (file)
--- a/iolog.h
+++ b/iolog.h
@@ -122,7 +122,8 @@ static inline size_t log_entry_sz(struct io_log *log)
 static inline struct io_sample *__get_sample(void *samples, int log_offset,
                                             uint64_t sample)
 {
-       return samples + sample * __log_entry_sz(log_offset);
+       uint64_t sample_offset = sample * __log_entry_sz(log_offset);
+       return (struct io_sample *) ((char *) samples + sample_offset);
 }
 
 static inline struct io_sample *get_sample(struct io_log *iolog,