pgsql: Get rid of ojrelid local variable in remove_rel_from_query()

From: Alexander Korotkov <akorotkov(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Get rid of ojrelid local variable in remove_rel_from_query()
Date: 2025-02-27 09:28:01
Message-ID: E1tnaBT-000Jvg-2N@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Get rid of ojrelid local variable in remove_rel_from_query()

As spotted by Coverity, the calculation of ojrelid mixes signed and unsigned
types causes possible overflow and undefined behavior. Instead of trying to
fix the expression, this commit eliminates the relied local variable. The
explicit branching is used to replace the -1 value. That, in turn, requires
changing the signature of the remove_rel_from_eclass() function.

Reported-by: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Discussion: https://postgr.es/m/914330.1740330169%40sss.pgh.pa.us
Reviewed-by: Andrei Lepikhov <lepihov(at)gmail(dot)com>

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/e167191dc146b65146fbd32e147be30dd8f1f166

Modified Files
--------------
src/backend/optimizer/plan/analyzejoins.c | 81 ++++++++++++++++++++-----------
1 file changed, 53 insertions(+), 28 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2025-02-27 15:58:27 pgsql: Get rid of O(N^2) script-parsing overhead in pgbench.
Previous Message Thomas Munro 2025-02-27 07:51:28 pgsql: Remove arbitrary cap on read_stream.c buffer queue.