All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: "Daniel P. Berrangé" <berrange@redhat.com>
Cc: BALATON Zoltan <balaton@eik.bme.hu>,
	qemu-devel@nongnu.org, qemu-trivial@nongnu.org,
	 Laurent Vivier <laurent@vivier.eu>
Subject: Re: [PATCH v2] Drop more useless casts from void * to pointer
Date: Wed, 23 Nov 2022 16:08:24 +0100	[thread overview]
Message-ID: <871qpt674n.fsf@pond.sub.org> (raw)
In-Reply-To: <Y34on7NQk44e07cM@redhat.com> ("Daniel P. Berrangé"'s message of "Wed, 23 Nov 2022 14:05:19 +0000")

Daniel P. Berrangé <berrange@redhat.com> writes:

> On Wed, Nov 23, 2022 at 02:51:49PM +0100, BALATON Zoltan wrote:
>> On Wed, 23 Nov 2022, Markus Armbruster wrote:
>> > Signed-off-by: Markus Armbruster <armbru@redhat.com>
>> > Reviewed-by: Laurent Vivier <laurent@vivier.eu>
>> > ---
>> > v2:
>> > * PATCH 1+2 merged as commit 0a553c12c7 and 3f7febc937
>> > * PATCH 3 change to util/coroutine-ucontext.c dropped [Laurent]
>> > 
>> > bsd-user/elfload.c                      | 2 +-
>> > contrib/plugins/cache.c                 | 8 ++++----
>> > contrib/vhost-user-blk/vhost-user-blk.c | 2 +-
>> > hw/core/qdev-clock.c                    | 2 +-
>> > hw/hyperv/vmbus.c                       | 2 +-
>> > hw/net/cadence_gem.c                    | 2 +-
>> > hw/net/virtio-net.c                     | 2 +-
>> > hw/nvme/ctrl.c                          | 4 ++--
>> > hw/rdma/vmw/pvrdma_cmd.c                | 9 +++------
>> > hw/rdma/vmw/pvrdma_qp_ops.c             | 6 +++---
>> > hw/virtio/virtio-iommu.c                | 3 +--
>> > linux-user/syscall.c                    | 2 +-
>> > target/i386/hax/hax-all.c               | 2 +-
>> > tests/tcg/aarch64/system/semiheap.c     | 4 ++--
>> > util/vfio-helpers.c                     | 2 +-
>> > 15 files changed, 24 insertions(+), 28 deletions(-)
>> > 
>> > diff --git a/bsd-user/elfload.c b/bsd-user/elfload.c
>> > index f8edb22f2a..fbcdc94b96 100644
>> > --- a/bsd-user/elfload.c
>> > +++ b/bsd-user/elfload.c
>> > @@ -156,7 +156,7 @@ static abi_ulong copy_elf_strings(int argc, char **argv, void **page,
>> >             --p; --tmp; --len;
>> >             if (--offset < 0) {
>> >                 offset = p % TARGET_PAGE_SIZE;
>> > -                pag = (char *)page[p / TARGET_PAGE_SIZE];
>> > +                pag = page[p / TARGET_PAGE_SIZE];
>> 
>> I think arithmetic on void pointer was undefined at least in the past so
>> some compilers may warn for it but not sure if this is still the case for
>> the compilers we care about. Apparently not if this now compiles but that
>> explains why this cast was not useless.

I don't think so :)

@pag is char *.

@page is void **.

page[p / TARGET_PAGE_SIZE] is void *.  No need to cast to char * before
assigning to @pag.

No pointer arithmetic so far.  There's some further down: pag + offset.
@pag is char * before and after my patch.

>>                                         Found some more info on this here:
>> 
>> https://stackoverflow.com/questions/3523145/pointer-arithmetic-for-void-pointer-in-c
>
> QEMU explicitly only targets GCC + Clang, so portability to other
> compilers is not required.

Correct.  We do arithmentic with void * in many places already.

If we cared for portability to other compilers, we'd enable

'-Wpointer-arith'
     Warn about anything that depends on the "size of" a function type
     or of 'void'.  GNU C assigns these types a size of 1, for
     convenience in calculations with 'void *' pointers and pointers to
     functions.  In C++, warn also when an arithmetic operation involves
     'NULL'.  This warning is also enabled by '-Wpedantic'.

But we don't.



  reply	other threads:[~2022-11-23 15:08 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-23 13:38 [PATCH v2] Drop more useless casts from void * to pointer Markus Armbruster
2022-11-23 13:51 ` BALATON Zoltan
2022-11-23 14:05   ` Daniel P. Berrangé
2022-11-23 15:08     ` Markus Armbruster [this message]
2022-11-23 16:29       ` BALATON Zoltan
2022-11-23 18:04         ` Markus Armbruster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=871qpt674n.fsf@pond.sub.org \
    --to=armbru@redhat.com \
    --cc=balaton@eik.bme.hu \
    --cc=berrange@redhat.com \
    --cc=laurent@vivier.eu \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.