[Spice-devel] [PATCH] Add casts for compatibility purposes

Dan McGee dpmcgee at gmail.com
Mon Feb 13 11:53:32 PST 2012


Some non-Linux platforms return a (caddr_t *) result for the return
value of mmap(), which is very unfortunate. Add a (void *) cast to
explicitly avoid the warning when compiling with -Werror.

For the IO vector related stuff, signed vs. unsigned comes into play so
adding a (void *) cast here is technically correct for all platforms.

Signed-off-by: Dan McGee <dpmcgee at gmail.com>
---

We don't fully compile on non-Linux platforms due to epoll() usage, but future
patches I have planned might change that. This is just one small patch to make
it easier to focus exclusively on the epoll stuff.

 common/marshaller.c |    2 +-
 server/reds.c       |    2 +-
 tools/reds_stat.c   |    2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/common/marshaller.c b/common/marshaller.c
index 1446df8..9023d08 100644
--- a/common/marshaller.c
+++ b/common/marshaller.c
@@ -525,7 +525,7 @@ int spice_marshaller_fill_iovec(SpiceMarshaller *m, struct iovec *vec,
             if (v == n_vec) {
                 return v; /* Not enough space in vec */
             }
-            vec[v].iov_base = item->data + skip_bytes;
+            vec[v].iov_base = (void *)item->data + skip_bytes;
             vec[v].iov_len = item->len - skip_bytes;
             skip_bytes = 0;
             v++;
diff --git a/server/reds.c b/server/reds.c
index 828ba65..ab0dfaf 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -3623,7 +3623,7 @@ static int do_spice_init(SpiceCoreInterface *core_interface)
     if (ftruncate(fd, REDS_STAT_SHM_SIZE) == -1) {
         red_error("statistics ftruncate failed, %s", strerror(errno));
     }
-    reds->stat = mmap(NULL, REDS_STAT_SHM_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+    reds->stat = (SpiceStat *)mmap(NULL, REDS_STAT_SHM_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
     if (reds->stat == (SpiceStat *)MAP_FAILED) {
         red_error("statistics mmap failed, %s", strerror(errno));
     }
diff --git a/tools/reds_stat.c b/tools/reds_stat.c
index 39d17af..5e9705c 100644
--- a/tools/reds_stat.c
+++ b/tools/reds_stat.c
@@ -84,7 +84,7 @@ int main(int argc, char **argv)
         return -1;
     }
     shm_size = sizeof(SpiceStat);
-    reds_stat = mmap(NULL, shm_size, PROT_READ, MAP_SHARED, fd, 0);
+    reds_stat = (SpiceStat *)mmap(NULL, shm_size, PROT_READ, MAP_SHARED, fd, 0);
     if (reds_stat == (SpiceStat *)MAP_FAILED) {
         perror("mmap");
         goto error1;
-- 
1.7.9



More information about the Spice-devel mailing list