Re: Suspicious strcmp() in src/backend/parser/parse_expr.c

From: Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>
To: Rikard Falkeborn <rikard(dot)falkeborn(at)gmail(dot)com>
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: Suspicious strcmp() in src/backend/parser/parse_expr.c
Date: 2019-04-10 22:33:35
Message-ID: 87pnptwl1a.fsf@news-spur.riddles.org.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

>>>>> "Rikard" == Rikard Falkeborn <rikard(dot)falkeborn(at)gmail(dot)com> writes:

Rikard> In src/backend/parser/parse_expr.c the following snippet of code is found
Rikard> (lines 3238-3242, rev 765525c8c2c6e55abe):

Rikard> if (strcmp(*nodename, "+") == 0 ||
Rikard> strcmp(*nodename, "-")) // <-- notice the lack of comparisson
Rikard> here
Rikard> group = 0;
Rikard> else
Rikard> group = PREC_GROUP_PREFIX_OP;

Rikard> Should the second part of the || be strcmp(*nodename, "-") ==
Rikard> 0?

Yes it should.

The effect of this bug is to produce a false operator precedence warning
when those are enabled, like so:

postgres=# set operator_precedence_warning = on;
SET
postgres=# select -random() is null;
WARNING: operator precedence change: IS is now lower precedence than -

when in fact "-random() is null" always did parse as "(-random()) is null"
making the warning spurious.

--
Andrew (irc:RhodiumToad)

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2019-04-10 22:43:32 Re: Suspicious strcmp() in src/backend/parser/parse_expr.c
Previous Message Rikard Falkeborn 2019-04-10 21:40:53 Suspicious strcmp() in src/backend/parser/parse_expr.c