Skip to contentSkip to conversation

block/io: do not do pointer arithmetic on void *

RFC In review Vladimir Sementsov-Ogievskiy 4 participants 4 messages Mar 18, 2020 – Mar 20, 2020 Block layer

lore
Share & tools
lore
#0 lore raw

RFC 1/1 block/io: do not do pointer arithmetic on void *

---

Hi all!

C standard doesn't allow pointer arithmetic on void *. Still, gcc allows it as an extension:
https://gcc.gnu.org/onlinedocs/gcc-4.8.0/gcc/Pointer-Arith.html

I can create a series of patches like this. Do we need it?

Also, where is documented which compilers are supported by Qemu?

 block/io.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/io.c +1 -1
index aba67f66b9..539178aed5 100644
@@ -1277,7 +1277,7 @@ static int coroutine_fn bdrv_co_do_copy_on_readv(BdrvChild *child,
      * modifying the image file.  This is critical for zero-copy guest I/O
      * where anything might happen inside guest memory.
      */
-    void *bounce_buffer = NULL;
+    char *bounce_buffer = NULL;
 
     BlockDriver *drv = bs->drv;
     int64_t cluster_offset;
Signature · 1 line
2.21.0
#1 lore raw
Quoted 10 lines · Vladimir Sementsov-Ogievskiy

---

Hi all!

C standard doesn't allow pointer arithmetic on void *. Still, gcc allows it as an extension:
https://gcc.gnu.org/onlinedocs/gcc-4.8.0/gcc/Pointer-Arith.html

I can create a series of patches like this. Do we need it?

I don't think so, we only care about gcc & clang.

Quoted 1 line

Also, where is documented which compilers are supported by Qemu?

It is checked in configure - gcc 4.8 or clang 3.4 or xcode clang 5.1

Quoted 21 lines
 block/io.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/io.c +1 -1
index aba67f66b9..539178aed5 100644
@@ -1277,7 +1277,7 @@ static int coroutine_fn bdrv_co_do_copy_on_readv(BdrvChild *child,
      * modifying the image file.  This is critical for zero-copy guest I/O
      * where anything might happen inside guest memory.
      */
-    void *bounce_buffer = NULL;
+    char *bounce_buffer = NULL;
 
     BlockDriver *drv = bs->drv;
     int64_t cluster_offset;
Signature · 1 line
2.21.0

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#2 lore raw
Quoted 6 lines · Daniel P. Berrangé
Quoted 5 lines · Vladimir Sementsov-Ogievskiy

---

Hi all!

Quoted 7 lines
Quoted 5 lines

C standard doesn't allow pointer arithmetic on void *. Still, gcc allows it as an extension:
https://gcc.gnu.org/onlinedocs/gcc-4.8.0/gcc/Pointer-Arith.html

I can create a series of patches like this. Do we need it?

I don't think so, we only care about gcc & clang.

Still, if all supported compilers support the extension, then our CODING_STYLE.rst should mention that it is safe to rely on the extension.

Quoted 5 lines
Quoted 2 lines

Also, where is documented which compilers are supported by Qemu?

It is checked in configure - gcc 4.8 or clang 3.4 or xcode clang 5.1

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#3 lore raw
In reply to Daniel P. Berrangé
Quoted 6 lines · Daniel P. Berrangé
Quoted 5 lines · Vladimir Sementsov-Ogievskiy

---

Hi all!

Quoted 7 lines
Quoted 5 lines

C standard doesn't allow pointer arithmetic on void *. Still, gcc allows it as an extension:
https://gcc.gnu.org/onlinedocs/gcc-4.8.0/gcc/Pointer-Arith.html

I can create a series of patches like this. Do we need it?

I don't think so, we only care about gcc & clang.

I agree with Dan.

Stefan