BUG #19066: postgresql-18.0/src/backend/optimizer/geqo/geqo_ox2.c:86: Array index check in wrong place ?

PG Bug reporting form <noreply@postgresql.org>

From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: dcb314@hotmail.com
Date: 2025-09-26T09:51:09Z
Lists: pgsql-bugs
The following bug has been logged on the website:

Bug reference:      19066
Logged by:          David Binderman
Email address:      dcb314@hotmail.com
PostgreSQL version: 18.0
Operating system:   fedora 42
Description:        

Static analyser cppcheck says:

postgresql-18.0/src/backend/optimizer/geqo/geqo_ox2.c:86:22: style: Array
index 'j' is used before limits check. [arrayIndexThenCheck]

Source code is

  while ((city_table[j].select_list == -1) && (j < num_gene))

Suggest new source code

  while ((j < num_gene) && (city_table[j].select_list == -1))