nbtpage.c:356 Expression 'metad->btm_root != P_NONE' is always false.

Started by Антон Пацевover 5 years ago2 messageshackers
Jump to latest
#1Антон Пацев
patsev.anton@gmail.com

Hello!
I am trying to help for Project PostgreSQL. Check source code PostgreSQL by
PVS-Studio.
PVS-Studio have many issue, but some issue is interesting.
nbtpage.c:356 <http://localhost/sources/nbtpage.c_24.html#ln356&gt; *High* V547
<https://www.viva64.com/en/w/v547/&gt; Expression 'metad->btm_root != 0' is
always false.
Source file src/backend/access/nbtree/nbtpage.c

if (metad->btm_root == P_NONE)
{
Page metapg;
/* If access = BT_READ, caller doesn't want us to create root yet */
if (access == BT_READ)
{
_bt_relbuf(rel, metabuf);
return InvalidBuffer;
}
/* trade in our read lock for a write lock */
_bt_unlockbuf(rel, metabuf);
_bt_lockbuf(rel, metabuf, BT_WRITE);
/*
* Race condition: if someone else initialized the metadata between
* the time we released the read lock and acquired the write lock, we
* must avoid doing it again.
*/
if (metad->btm_root != P_NONE)

↑ V547 <https://www.viva64.com/en/w/v547/&gt; Expression 'metad->btm_root !=
0' is always false.

--
С уважением, Антон Пацев.
Best regards, Anton Patsev.

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Антон Пацев (#1)
Re: nbtpage.c:356 Expression 'metad->btm_root != P_NONE' is always false.

=?UTF-8?B?0JDQvdGC0L7QvSDQn9Cw0YbQtdCy?= <patsev.anton@gmail.com> writes:

I am trying to help for Project PostgreSQL. Check source code PostgreSQL by
PVS-Studio.
PVS-Studio have many issue, but some issue is interesting.
nbtpage.c:356 <http://localhost/sources/nbtpage.c_24.html#ln356&gt; *High* V547
<https://www.viva64.com/en/w/v547/&gt; Expression 'metad->btm_root != 0' is
always false.

This is incorrect. The tool apparently doesn't understand that the
storage pointed to by metad can be changed by other processes in the
interval where we don't hold a lock on the buffer.

regards, tom lane