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 1sH4GY-002krD-0m for pgsql-hackers@arkaria.postgresql.org; Tue, 11 Jun 2024 16:22:34 +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 1sH4GW-007o3W-EK for pgsql-hackers@arkaria.postgresql.org; Tue, 11 Jun 2024 16:22:33 +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 1sH4GW-007o3O-4d for pgsql-hackers@lists.postgresql.org; Tue, 11 Jun 2024 16:22:33 +0000 Received: from mail-io1-xd30.google.com ([2607:f8b0:4864:20::d30]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sH4GU-000or1-Ia for pgsql-hackers@lists.postgresql.org; Tue, 11 Jun 2024 16:22:31 +0000 Received: by mail-io1-xd30.google.com with SMTP id ca18e2360f4ac-7eb7c5b12e3so52095139f.3 for ; Tue, 11 Jun 2024 09:22:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718122949; x=1718727749; darn=lists.postgresql.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=S0h7ndgWaIraAf0ZU7CFm3GiWcVYd93Ftq7WUHo13Zc=; b=Odyi0pCnBKTOrdwtq8Q5phi5+HSmd2ZZMGc+THmS9hFUu0gWBSSO93ULRo9qHh5mSd 8qTRzvlBRsmCEv+ODNVaaE1Z2CMphX14S4fcv+U86+9mjHVvvLWUU6ZTzjHh/QoGbNdi PZwH0eaosi2LHw0ll0XhgOz+u/ynAWd7I8dzjdaNvmUIbUFycGRPKUD5fcS+DdqJ8uMB 3OCSITwKHk3w0z8e0zgJl3A0GJ4mEHCw+furM1SMrx5uzcL3O9LZBwW0KNLTBN+ZjMz2 RScMOCXzeyxNdpuoqflSxT2C/nS7KidB5MKKBfr4EOeTv4d+NO2AoJquEEZ3yg2tajxX 56/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718122949; x=1718727749; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=S0h7ndgWaIraAf0ZU7CFm3GiWcVYd93Ftq7WUHo13Zc=; b=lTy5HlcogTSQfIkc0komFYZZaEq6EN53Np1+vkBnnbKnJEHLdKS4PjGUrTCprssbUe GmReEgmz5mfaOphPSL0q6P3Q/tXaPHl2sd3H5UUIZn5LvKUfjNZX5ccj67bLjCn26J+H ZCWIzDjDySoeRjpQNp1cgkjzavUnRKaDOVfYhMMcSYP/lHA9poSWroicM/ZCi9+Y/BtK /s1DDq1ep8lNx0W7YYlhF9dE5ySIArR3FLSoUh1iS6ragFa4FkyoFXTAWMUwfmZqNNp5 Q8ycRJx3ApFWDYbdvNOpudNhnzlS3U3iRffx5+B/H0s+IlRWHlr7nJlT3B4gVlInPM+6 ZUwg== X-Forwarded-Encrypted: i=1; AJvYcCWV6cgBrtv93lHt2Mq4iCIt+U4wkPay6xNPpFctA8bfIPEt0etX30ubHb+S/4ZiNIoHDMFwn7cszIeZuvLMw0jIFQ9DlMOcOq12can1rD4jQQso X-Gm-Message-State: AOJu0Yywh4CnRKIU6AzEDTCX512OcE4LpumIPp7Wdcwk6DJFsqTmzbf8 hdd2OmevbiEGH90BdQNAJxish0S7Isu5RVSGp1RCARrTXnE26wwj X-Google-Smtp-Source: AGHT+IG1pBAgx8WD1NMFXDQcRZhOlS2hUDURV7RzS+RsruA0Sa4gvCRDEqOC4vcLSCoSX9w9a4FKkQ== X-Received: by 2002:a05:6602:1587:b0:7eb:8320:3662 with SMTP id ca18e2360f4ac-7eb83203a29mr753266339f.19.1718122949580; Tue, 11 Jun 2024 09:22:29 -0700 (PDT) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id ca18e2360f4ac-7eb7e46bc83sm143873439f.41.2024.06.11.09.22.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 09:22:29 -0700 (PDT) Date: Tue, 11 Jun 2024 11:22:27 -0500 From: Nathan Bossart To: Joseph Koshakow Cc: Andres Freund , Tom Lane , PostgreSQL Hackers Subject: Re: Remove dependence on integer wrapping Message-ID: References: <618777.1717984674@sss.pgh.pa.us> <20240610183031.fxyh5lug2i273jj4@awork3.anarazel.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Jun 11, 2024 at 09:31:39AM -0400, Joseph Koshakow wrote: > tmp is an uint16 here, it seems like you might have read it as an > int16? We would need some helper method like > > static inline bool > pg_neg_u16_overflow(uint16 a, int16 *result); > > and then we could replace that whole chunk with something like > > if (unlikely(pg_neg_u16_overflow(tmp, &result))) > goto out_of_range; > else > return result; > > > that pattern shows up a lot in this file, but I was worried that it > wasn't useful as a general purpose function. Happy to add it > though if you still feel otherwise. I personally find that much easier to read. Since the existing open-coded overflow check is apparently insufficient, I think there's a reasonably strong case for centralizing this sort of thing so that we don't continue to make the same mistakes. >> Ah, I see. Joe's patch does that in one place. It's probably worth doing >> that in the other places this "just-barefly overflow" comment appears >> IMHO. > > The only other place I found this comment was in > `make_timestamp_internal`. I've updated that function and added some > tests. I also manually verified that the behavior matches before and > after this patch. tm2timestamp() in src/interfaces/ecpg/pgtypeslib/timestamp.c has the same comment. The code there looks very similar to the code for tm2timestamp() in the other timestamp.c... -- nathan