Re: Andres Freund 2017-12-13 <20171213173524.rjs7b3ahsong5...@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 <m...@debian.org> wrote: > > > Re: Andres Freund 2017-12-13 <e1eovqf-00075r...@gemulon.postgresql.org> > > >> 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
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. */