Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ePOsN-0001vQ-NF for pgsql-hackers@arkaria.postgresql.org; Thu, 14 Dec 2017 08:28:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ePOsM-0007Gk-RM for pgsql-hackers@arkaria.postgresql.org; Thu, 14 Dec 2017 08:28:18 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ePOsM-0007Ga-I0 for pgsql-hackers@lists.postgresql.org; Thu, 14 Dec 2017 08:28:18 +0000 Received: from feynman.df7cb.de ([195.49.152.168]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1ePOsI-0006Gf-M7 for pgsql-hackers@postgresql.org; Thu, 14 Dec 2017 08:28:17 +0000 Received: from msg.df7cb.de (unknown [IPv6:2003:5b:203b:100:7627:eaff:fe52:8e03]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by feynman.df7cb.de (Postfix) with ESMTPSA id 3yy6Bw3frcz3Dyv; Thu, 14 Dec 2017 09:28:08 +0100 (CET) Date: Thu, 14 Dec 2017 09:28:08 +0100 From: Christoph Berg To: Andres Freund Cc: pgsql-committers Subject: Re: pgsql: Provide overflow safe integer math inline functions. Message-ID: <20171214082808.GA5775@msg.df7cb.de> Mail-Followup-To: Christoph Berg , Andres Freund , pgsql-committers References: <20171213101037.GA28753@msg.df7cb.de> <20171213173524.rjs7b3ahsong5zko@alap3.anarazel.de> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="ReaqsoxgOBHFXBhH" Content-Disposition: inline In-Reply-To: <20171213173524.rjs7b3ahsong5zko@alap3.anarazel.de> User-Agent: Mutt/1.9.1 (2017-09-22) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --ReaqsoxgOBHFXBhH Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Re: Andres Freund 2017-12-13 <20171213173524.rjs7b3ahsong5zko@alap3.anarazel.de> > On 2017-12-13 09:37:25 -0500, Robert Haas wrote: > > On Wed, Dec 13, 2017 at 5:10 AM, Christoph Berg wrote: > > > Re: Andres Freund 2017-12-13 > > >> Provide overflow safe integer math inline functions. > > > > > > The new _overflow functions have buggy comments: > > > > > > /* > > > * If a - b overflows, return true, otherwise store the result of a + b into > > > * *result. ^ there > > > > What's wrong with that? > > After staring at it for a while, I seem to have partially mis-copied the > note for addition to the subtraction operation... I believe the attached is the correct version. Christoph --ReaqsoxgOBHFXBhH Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="int.h-comments" diff --git a/src/include/common/int.h b/src/include/common/int.h new file mode 100644 index e44d42f..e6907c6 *** a/src/include/common/int.h --- b/src/include/common/int.h *************** pg_add_s16_overflow(int16 a, int16 b, in *** 41,47 **** } /* ! * If a - b overflows, return true, otherwise store the result of a + b into * *result. The content of *result is implementation defined in case of * overflow. */ --- 41,47 ---- } /* ! * If a - b overflows, return true, otherwise store the result of a - b into * *result. The content of *result is implementation defined in case of * overflow. */ *************** pg_sub_s16_overflow(int16 a, int16 b, in *** 61,67 **** } /* ! * If a * b overflows, return true, otherwise store the result of a + b into * *result. The content of *result is implementation defined in case of * overflow. */ --- 61,67 ---- } /* ! * If a * b overflows, return true, otherwise store the result of a * b into * *result. The content of *result is implementation defined in case of * overflow. */ *************** pg_add_s32_overflow(int32 a, int32 b, in *** 101,107 **** } /* ! * If a - b overflows, return true, otherwise store the result of a + b into * *result. The content of *result is implementation defined in case of * overflow. */ --- 101,107 ---- } /* ! * If a - b overflows, return true, otherwise store the result of a - b into * *result. The content of *result is implementation defined in case of * overflow. */ *************** pg_sub_s32_overflow(int32 a, int32 b, in *** 121,127 **** } /* ! * If a * b overflows, return true, otherwise store the result of a + b into * *result. The content of *result is implementation defined in case of * overflow. */ --- 121,127 ---- } /* ! * If a * b overflows, return true, otherwise store the result of a * b into * *result. The content of *result is implementation defined in case of * overflow. */ *************** pg_add_s64_overflow(int64 a, int64 b, in *** 167,173 **** } /* ! * If a - b overflows, return true, otherwise store the result of a + b into * *result. The content of *result is implementation defined in case of * overflow. */ --- 167,173 ---- } /* ! * If a - b overflows, return true, otherwise store the result of a - b into * *result. The content of *result is implementation defined in case of * overflow. */ *************** pg_sub_s64_overflow(int64 a, int64 b, in *** 193,199 **** } /* ! * If a * b overflows, return true, otherwise store the result of a + b into * *result. The content of *result is implementation defined in case of * overflow. */ --- 193,199 ---- } /* ! * If a * b overflows, return true, otherwise store the result of a * b into * *result. The content of *result is implementation defined in case of * overflow. */ --ReaqsoxgOBHFXBhH--