Get rid of ojrelid local variable in remove_rel_from_query()
authorAlexander Korotkov <akorotkov@postgresql.org>
Sun, 23 Feb 2025 21:06:33 +0000 (23:06 +0200)
committerAlexander Korotkov <akorotkov@postgresql.org>
Thu, 27 Feb 2025 09:22:01 +0000 (11:22 +0200)
commite167191dc146b65146fbd32e147be30dd8f1f166
tree72c7259136d84c452c9527bbe3dd40b76312b0cf
parent55918f798bc2d1846eea0d805fbec91d4e1816e0
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@sss.pgh.pa.us>
Discussion: https://postgr.es/m/914330.1740330169%40sss.pgh.pa.us
Reviewed-by: Andrei Lepikhov <lepihov@gmail.com>
src/backend/optimizer/plan/analyzejoins.c