Re: Greatest Common Divisor

From: Vik Fearing <vik(dot)fearing(at)2ndquadrant(dot)com>
To: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Stephen Frost <sfrost(at)snowman(dot)net>, Chapman Flack <chap(at)anastigmatix(dot)net>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Greatest Common Divisor
Date: 2020-01-26 05:52:05
Message-ID: 6e879afa-3055-3d63-6fb7-fbebcd49d5d5@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 25/01/2020 15:18, Dean Rasheed wrote:
>
> Committed with some adjustments, mostly cosmetic but a couple more substantive:

Thanks!

> The code to guard against a floating point exception with inputs of
> (INT_MIN, -1) wasn't quite right because it actually just moved the
> problem so that it would fall over with inputs of (INT_MIN, +1).

Good catch.

> The convention in numeric.c is that the xxx_var() functions take
> *pointers* to their NumericVar arguments rather than copies, and they
> do not modify their inputs, as indicated by the use of "const". You
> might just have gotten away with what you were doing, but I think it
> was bad style and potentially unsafe -- for example, someone calling
> gcd_var() with a NumericVar that came from some other computation and
> having a non-null buf would risk having the buf freed in the copy,
> leaving the original NumericVar with a buf pointing to freed memory.

Thank you for taking the time to look closely at this. This was my
first time dealing with "numeric" so I was bound to make some mistakes.
--
Vik Fearing

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Heikki Linnakangas 2020-01-26 09:40:05 Re: Remove page-read callback from XLogReaderState.
Previous Message Justin Pryzby 2020-01-26 05:36:29 Re: vacuum verbose detail logs are unclear; log at *start* of each stage