From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTP id 27B7E5A0279 for ; Thu, 30 Nov 2023 10:07:07 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701335226; 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=QXUkfm0dCMMjbh6UvIWA01vuwPDJwR+s5xluOjv3wYA=; b=C1f+Tu6typSV6dnKHaRM6pJPVyZ8gN9eZPW1XSO0c6fl8MWMaWO23BVf1zxMU7W2IUHntx j1eUAcVbPnq9yIQ8oGkSrkP5dOml6AP2zoRVSSMvzouxBDpZMd6QmfAasBRLlXhDmSqEVh xPXFGhWSgjR1NkuatqV+uenwo8FNDUI= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-517-V5trhID_NtG30GJI24oMmw-1; Thu, 30 Nov 2023 04:07:04 -0500 X-MC-Unique: V5trhID_NtG30GJI24oMmw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id C854C1C2B677; Thu, 30 Nov 2023 09:07:03 +0000 (UTC) Received: from elisabeth (unknown [10.39.208.34]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C51D61121307; Thu, 30 Nov 2023 09:07:02 +0000 (UTC) Date: Thu, 30 Nov 2023 10:07:00 +0100 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 2/4] packet: Offset plus length is not always uint32_t, but it's always size_t Message-ID: <20231130100700.10fe5354@elisabeth> In-Reply-To: References: <20231129134610.3796809-1-sbrivio@redhat.com> <20231129134610.3796809-3-sbrivio@redhat.com> Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: 7RYEBNB7BCAVL3624KWNVDD26PN73ZPL X-Message-ID-Hash: 7RYEBNB7BCAVL3624KWNVDD26PN73ZPL X-MailFrom: sbrivio@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: passt-dev@passt.top, lemmi@nerd2nerd.org 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: On Thu, 30 Nov 2023 11:18:48 +1100 David Gibson wrote: > On Wed, Nov 29, 2023 at 02:46:08PM +0100, Stefano Brivio wrote: > > According to gcc, PRIu32 matches the type of the argument we're > > printing here on both 64 and 32-bits architectures. According to > > Clang, though, that's not the case, as the result of the sum is an > > unsigned long on 64-bit. > > > > Use the z modifier, given that we're summing uint32_t to size_t, and > > the result is at most promoted to size_t. > > Heh, sorry, obviously hadn't read this patch when I commented on this > spot in the first one. The problem here is that the final promoted > type depends on whether size_t is wider than uint32_t or not, which > can vary with architecture. ...I'm not sure if it's just a matter of warnings, but gcc is perfectly happy with PRIu32 for uint32_t + size_t on x86_64, so on top of the architecture, promotion rules also seem to vary between compilers. Or maybe it just doesn't complain about the possible format truncation. > That said, I doubt we're likely to support anything with a size_t > strictly *less* than 32-bits, so %zu is probably safe. Ah, yes, I took that for granted. Looking into older architectures where C would commonly be used, it looks like 16 bits of size_t would only suffice for *selected versions* of PDP-11 (PDP-11/15 and PDP-11/20, but not PDP-11/45 already, because the addressing space is larger than 64 KiB). Indeed there are 8 and 16 bits processors, but there doesn't appear to be any other modern architecture where 16 bits suffice for addressable memory (by design). -- Stefano