Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tRcXk-00AghN-GG for pgsql-hackers@arkaria.postgresql.org; Sat, 28 Dec 2024 19:32:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tRcWj-0020qM-Ny for pgsql-hackers@arkaria.postgresql.org; Sat, 28 Dec 2024 19:31:09 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tRcWj-0020qE-Eg for pgsql-hackers@lists.postgresql.org; Sat, 28 Dec 2024 19:31:09 +0000 Received: from momjian.us ([72.94.173.45]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tRcWe-000zhq-1G for pgsql-hackers@lists.postgresql.org; Sat, 28 Dec 2024 19:31:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=momjian.us; s=2024011501; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID: Subject:To:From:Date:Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description; bh=dqp8qcOqS6RAMMfyWVWJ1fG5ODz8Hit1AsLG3dPpfAs=; b=IxgL3 AUWewY5KL5BS7dDTA8xjLdF0fxpg07cUd28L1MDumG53yTpqA7pw92xhy6iMDDVkMTLVg8gKCp8vU j8gDMTLiznr9/C83M5poA/n1uu+9zGTICDjnCajxfwbXsEPO4zPkqa8wH38AKJOwkd10xAv7gm0z4 07FjdNkqrJ0+VCcMLpE46WomYxG3w4c5vVz0vc0TihI993QdDtCYpcl+mAe5tume4MmuG+z6dh3pz jgriyEDjtNFqOz3ao8J0Bs/q3oFiYKzvOI7aeIgtFiCjQRMkDSgdu8r1b64isU75RJImXeqwdNLlD hvEQd774R6Sl8ZWSCN8DeYTHBXsUQ==; Received: from bruce by momjian.us with local (Exim 4.96) (envelope-from ) id 1tRcWd-000oIj-0E; Sat, 28 Dec 2024 14:31:03 -0500 Date: Sat, 28 Dec 2024 14:31:03 -0500 From: Bruce Momjian To: scrooll@gmail.com, PostgreSQL-development Subject: Re: which wire protocol fields are signed int and which ones are unsigned Message-ID: References: <173383182751.3842594.15469565442916458038@wrigleys.postgresql.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <173383182751.3842594.15469565442916458038@wrigleys.postgresql.org> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Dec 10, 2024 at 11:57:07AM +0000, PG Doc comments form wrote: > The following documentation comment has been logged on the website: > > Page: https://www.postgresql.org/docs/17/protocol-message-formats.html > Description: > > I don't see it clearly stated which Int fields are signed and which are > unsigned. If it can be assumed that Int is signed and Byte is unsigned then > the object id fields are wrong because they should be unsigned. (Thead moved to hackers since it involves internals issues.) This is a very good point. I looked at the backend code and couldn't find a clear answer. For example, let's look at AuthenticationOk, which uses src/backend/libpq/auth.c::sendAuthRequest(). You have "AuthRequest" passed in as an unsigned int32, stored in StringInfoData.cursor as a signed int32, passed to pq_sendint32() as a signed int32, which gets passed to pq_writeint32(), which casts it back to a unsigned int32 to send on the socket. For the length of AuthenticationOk, it uses StringInfo.len, which is a signed int32, but that is cast by /pgtop/src/backend/libpq/pqcomm.c::socket_putmessage() to unsigned int32 in () before sending it on the socket. Why is StringInfo.len a signed int? Do we need to use -1 in that field? Do we not expect that to exceed 2GB? A related issue is that the format our docs use for this is confusing. Is Byte1 signed or unsigned. Can we assume Int32 is signed since it is in C? (In C, the sign of "char" is undetermined.) We display the data type and value as "Int32(8)", which looks more like a function call than what is represents. Any ideas on how to improvem that? -- Bruce Momjian https://momjian.us EDB https://enterprisedb.com Do not let urgent matters crowd out time for investment in the future.