Re: New Defects reported by Coverity Scan for PostgreSQL

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Ning Yu <nyu(at)pivotal(dot)io>
Cc: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tomas Vondra <tomas(dot)vondra(at)2ndquadrant(dot)com>, Emre Hasegeli <emre(at)hasegeli(dot)com>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: New Defects reported by Coverity Scan for PostgreSQL
Date: 2018-08-01 02:22:16
Message-ID: 26769.1533090136@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers pgsql-hackers

Ning Yu <nyu(at)pivotal(dot)io> writes:
> From my point of view it's better to also put some comments for humans to
> understand why we are passing l1 and l2 in reverse order.

The header comment for lseg_closept_lseg() is pretty far from adequate
as well. After studying it for awhile I think I've puzzled out the
indeterminacies, but I shouldn't have had to. I think it probably
should have read

* Closest point on line segment l2 to line segment l1
*
* This returns the minimum distance from l1 to the closest point on l2.
* If result is not NULL, the closest point on l2 is stored at *result.

Or perhaps I have it backwards and "l1" and "l2" need to be swapped in
that description. But the mere fact that there is any question about
that means that the function is poorly documented and perhaps poorly
named as well. For that matter, is there a good reason why l1/l2
have those roles and not the reverse?

While Coverity is surely operating from a shaky heuristic here, it's
got a point. The fact that it makes a difference which argument is
given first means that you've got to be really careful about which
is which, and this API spec is giving no help in that regard at all.

regards, tom lane

In response to

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Peter Eisentraut 2018-08-01 08:23:20 pgsql: Allow multi-inserts during COPY into a partitioned table
Previous Message Ning Yu 2018-08-01 00:08:13 Re: New Defects reported by Coverity Scan for PostgreSQL

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2018-08-01 02:44:32 Re: Should contrib modules install .h files?
Previous Message Kyotaro HORIGUCHI 2018-08-01 01:52:21 Re: [HACKERS] Restricting maximum keep segments by repslots