mirror of
https://github.com/postgres/postgres.git
synced 2025-10-18 04:29:09 +03:00
Fix Coverity issues reported in commit 25a30bbd42
.
Fix several issues pointed out by Coverity (reported by Tome Lane). - In row_is_in_frame(), return value of window_gettupleslot() was not checked. - WinGetFuncArgInPartition() tried to derefference "isout" pointer even if it could be NULL in some places. Besides the issues, I also fixed a compiler warning reported by Álvaro Herrera. Moreover, in WinGetFuncArgInPartition refactor the do...while loop so that the codes inside the loop simpler. Also simplify the case when abs_pos < 0. Author: Tatsuo Ishii <ishii@postgresql.org> Reviewed-by: Paul Ramsey <pramsey@cleverelephant.ca> Reported-by: Tom Lane <tgl@sss.pgh.pa.us> Reported-by: Álvaro Herrera <alvherre@kurilemu.de> Discussion: https://postgr.es/m/1686755.1759679957%40sss.pgh.pa.us Discussion: https://postgr.es/m/202510051612.gw67jlc2iqpw%40alvherre.pgsql
This commit is contained in:
@@ -1501,8 +1501,9 @@ row_is_in_frame(WindowObject winobj, int64 pos, TupleTableSlot *slot,
|
|||||||
/* following row that is not peer is out of frame */
|
/* following row that is not peer is out of frame */
|
||||||
if (pos > winstate->currentpos)
|
if (pos > winstate->currentpos)
|
||||||
{
|
{
|
||||||
if (fetch_tuple)
|
if (fetch_tuple) /* need to fetch tuple? */
|
||||||
window_gettupleslot(winobj, pos, slot);
|
if (!window_gettupleslot(winobj, pos, slot))
|
||||||
|
return -1;
|
||||||
if (!are_peers(winstate, slot, winstate->ss.ss_ScanTupleSlot))
|
if (!are_peers(winstate, slot, winstate->ss.ss_ScanTupleSlot))
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -3721,6 +3722,7 @@ WinGetFuncArgInPartition(WindowObject winobj, int argno,
|
|||||||
int notnull_offset;
|
int notnull_offset;
|
||||||
int notnull_relpos;
|
int notnull_relpos;
|
||||||
int forward;
|
int forward;
|
||||||
|
bool myisout;
|
||||||
|
|
||||||
Assert(WindowObjectIsValid(winobj));
|
Assert(WindowObjectIsValid(winobj));
|
||||||
winstate = winobj->winstate;
|
winstate = winobj->winstate;
|
||||||
@@ -3759,63 +3761,60 @@ WinGetFuncArgInPartition(WindowObject winobj, int argno,
|
|||||||
|
|
||||||
if (!null_treatment) /* IGNORE NULLS is not specified */
|
if (!null_treatment) /* IGNORE NULLS is not specified */
|
||||||
{
|
{
|
||||||
|
/* get tupple and evaluate in a partition */
|
||||||
datum = gettuple_eval_partition(winobj, argno,
|
datum = gettuple_eval_partition(winobj, argno,
|
||||||
abs_pos, isnull, isout);
|
abs_pos, isnull, &myisout);
|
||||||
if (!*isout && set_mark)
|
if (!myisout && set_mark)
|
||||||
WinSetMarkPosition(winobj, abs_pos);
|
WinSetMarkPosition(winobj, abs_pos);
|
||||||
|
if (isout)
|
||||||
|
*isout = myisout;
|
||||||
return datum;
|
return datum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
myisout = false;
|
||||||
|
datum = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the next nonnull value in the partition, moving forward or backward
|
* Get the next nonnull value in the partition, moving forward or backward
|
||||||
* until we find a value or reach the partition's end.
|
* until we find a value or reach the partition's end.
|
||||||
*/
|
*/
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
int nn_info; /* NOT NULL info */
|
||||||
|
|
||||||
abs_pos += forward;
|
abs_pos += forward;
|
||||||
if (abs_pos < 0)
|
if (abs_pos < 0) /* apparently out of partition */
|
||||||
{
|
|
||||||
/* out of partition */
|
|
||||||
if (isout)
|
|
||||||
*isout = true;
|
|
||||||
*isnull = true;
|
|
||||||
datum = 0;
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
switch (get_notnull_info(winobj, abs_pos))
|
/* check NOT NULL cached info */
|
||||||
|
nn_info = get_notnull_info(winobj, abs_pos);
|
||||||
|
if (nn_info == NN_NOTNULL) /* this row is known to be NOT NULL */
|
||||||
|
notnull_offset++;
|
||||||
|
|
||||||
|
else if (nn_info == NN_NULL) /* this row is known to be NULL */
|
||||||
|
continue; /* keep on moving forward or backward */
|
||||||
|
|
||||||
|
else /* need to check NULL or not */
|
||||||
{
|
{
|
||||||
case NN_NOTNULL: /* this row is known to be NOT NULL */
|
/* get tupple and evaluate in a partition */
|
||||||
|
datum = gettuple_eval_partition(winobj, argno,
|
||||||
|
abs_pos, isnull, &myisout);
|
||||||
|
if (myisout) /* out of partition? */
|
||||||
|
break;
|
||||||
|
if (!*isnull)
|
||||||
notnull_offset++;
|
notnull_offset++;
|
||||||
if (notnull_offset >= notnull_relpos)
|
/* record the row status */
|
||||||
{
|
put_notnull_info(winobj, abs_pos, *isnull);
|
||||||
/* prepare to exit this loop */
|
|
||||||
datum = gettuple_eval_partition(winobj, argno,
|
|
||||||
abs_pos, isnull, isout);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case NN_NULL: /* this row is known to be NULL */
|
|
||||||
if (isout)
|
|
||||||
*isout = false;
|
|
||||||
*isnull = true;
|
|
||||||
datum = 0;
|
|
||||||
break;
|
|
||||||
default: /* need to check NULL or not */
|
|
||||||
datum = gettuple_eval_partition(winobj, argno,
|
|
||||||
abs_pos, isnull, isout);
|
|
||||||
if (*isout) /* out of partition? */
|
|
||||||
return datum;
|
|
||||||
|
|
||||||
if (!*isnull)
|
|
||||||
notnull_offset++;
|
|
||||||
/* record the row status */
|
|
||||||
put_notnull_info(winobj, abs_pos, *isnull);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
} while (notnull_offset < notnull_relpos);
|
} while (notnull_offset < notnull_relpos);
|
||||||
|
|
||||||
if (!*isout && set_mark)
|
/* get tupple and evaluate in a partition */
|
||||||
|
datum = gettuple_eval_partition(winobj, argno,
|
||||||
|
abs_pos, isnull, &myisout);
|
||||||
|
if (!myisout && set_mark)
|
||||||
WinSetMarkPosition(winobj, abs_pos);
|
WinSetMarkPosition(winobj, abs_pos);
|
||||||
|
if (isout)
|
||||||
|
*isout = myisout;
|
||||||
|
|
||||||
return datum;
|
return datum;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user