From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=LeIjgkEi; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTPS id BD0605A027C for ; Tue, 13 May 2025 11:41:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747129271; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=a7zRAFt4oQ086CRQ34tYDdq/2tudBTIDsDuWywsBu1w=; b=LeIjgkEi3ewuKxd8PL0TdVfIFc23Sg+miEYZUfXJ/Xg3Dw1CeEhZaYMSwrhKAyKJG3GcgK 4el38Vfi3PnEPRiM3V0/XT93rNoDntykOwy2r1EztH+LXJqtL0+eefRdvqW6eygbe1z5xu U2VqbsH1+ZtyT+mmzWI27EDZShVw0PA= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-384-vvab4kErPfOOQTBTvy3epQ-1; Tue, 13 May 2025 05:41:09 -0400 X-MC-Unique: vvab4kErPfOOQTBTvy3epQ-1 X-Mimecast-MFC-AGG-ID: vvab4kErPfOOQTBTvy3epQ_1747129269 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1606819560BC for ; Tue, 13 May 2025 09:41:09 +0000 (UTC) Received: from lenovo-t14s.redhat.com (unknown [10.44.33.64]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 05391195396E; Tue, 13 May 2025 09:41:07 +0000 (UTC) From: Laurent Vivier To: passt-dev@passt.top Subject: [PATCH 2/4] virtio: Fix Clang warning (bugprone-sizeof-expression, cert-arr39-c) Date: Tue, 13 May 2025 11:41:00 +0200 Message-ID: <20250513094102.1372330-3-lvivier@redhat.com> In-Reply-To: <20250513094102.1372330-1-lvivier@redhat.com> References: <20250513094102.1372330-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: RYNeOGYrjrHdaDV1dhYZRyh95LyBY4InEZOMO58WUpQ_1747129269 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: PSYRQHFVWE4WWWXA7SLWSFF7YDJFEPGV X-Message-ID-Hash: PSYRQHFVWE4WWWXA7SLWSFF7YDJFEPGV X-MailFrom: lvivier@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Laurent Vivier X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: In `virtqueue_read_indirect_desc()`, the pointer arithmetic involving `desc` is intentional. We add the length in bytes (`read_len`) divided by the size of `struct vring_desc` to `desc`, which is an array of `struct vring_desc`. This correctly calculates the offset in terms of the number of `struct vring_desc` elements. Clang issues the following warning due to this explicit scaling: virtio.c:238:8: error: suspicious usage of 'sizeof(...)' in pointer arithmetic; this scaled value will be scaled again by the '+=' operator [bugprone-sizeof-expression,cert-arr39-c,-Werror] 238 | desc += read_len / sizeof(struct vring_desc); | ^ ~~~~~~~~~~~~~~~~~~~~~~~~~ virtio.c:238:8: note: '+=' in pointer arithmetic internally scales with 'sizeof(struct vring_desc)' == 16 This behavior is intended, so the warning can be considered a false positive in this context. The code correctly advances the pointer by the desired number of descriptor entries. Signed-off-by: Laurent Vivier --- virtio.c | 1 + 1 file changed, 1 insertion(+) diff --git a/virtio.c b/virtio.c index bc2b89a7f4a7..f7db0073b66c 100644 --- a/virtio.c +++ b/virtio.c @@ -235,6 +235,7 @@ static int virtqueue_read_indirect_desc(const struct vu_dev *dev, memcpy(desc, orig_desc, read_len); len -= read_len; addr += read_len; + /* NOLINTNEXTLINE(bugprone-sizeof-expression,cert-arr39-c) */ desc += read_len / sizeof(struct vring_desc); } -- 2.49.0