Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2273fa3

Browse files
committed
Fix Coverity issues reported in commit25a30bb.
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 ÁlvaroHerrera.Moreover, in WinGetFuncArgInPartition refactor the do...while loop sothat the codes inside the loop simpler. Also simplify the case whenabs_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.usDiscussion:https://postgr.es/m/202510051612.gw67jlc2iqpw%40alvherre.pgsql
1 parent3bf9056 commit2273fa3

File tree

1 file changed

+38
-39
lines changed

1 file changed

+38
-39
lines changed

‎src/backend/executor/nodeWindowAgg.c‎

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,8 +1501,9 @@ row_is_in_frame(WindowObject winobj, int64 pos, TupleTableSlot *slot,
15011501
/* following row that is not peer is out of frame */
15021502
if (pos>winstate->currentpos)
15031503
{
1504-
if (fetch_tuple)
1505-
window_gettupleslot(winobj,pos,slot);
1504+
if (fetch_tuple)/* need to fetch tuple? */
1505+
if (!window_gettupleslot(winobj,pos,slot))
1506+
return-1;
15061507
if (!are_peers(winstate,slot,winstate->ss.ss_ScanTupleSlot))
15071508
return-1;
15081509
}
@@ -3721,6 +3722,7 @@ WinGetFuncArgInPartition(WindowObject winobj, int argno,
37213722
intnotnull_offset;
37223723
intnotnull_relpos;
37233724
intforward;
3725+
boolmyisout;
37243726

37253727
Assert(WindowObjectIsValid(winobj));
37263728
winstate=winobj->winstate;
@@ -3759,63 +3761,60 @@ WinGetFuncArgInPartition(WindowObject winobj, int argno,
37593761

37603762
if (!null_treatment)/* IGNORE NULLS is not specified */
37613763
{
3764+
/* get tupple and evaluate in a partition */
37623765
datum=gettuple_eval_partition(winobj,argno,
3763-
abs_pos,isnull,isout);
3764-
if (!*isout&&set_mark)
3766+
abs_pos,isnull,&myisout);
3767+
if (!myisout&&set_mark)
37653768
WinSetMarkPosition(winobj,abs_pos);
3769+
if (isout)
3770+
*isout=myisout;
37663771
returndatum;
37673772
}
37683773

3774+
myisout= false;
3775+
datum=0;
3776+
37693777
/*
37703778
* Get the next nonnull value in the partition, moving forward or backward
37713779
* until we find a value or reach the partition's end.
37723780
*/
37733781
do
37743782
{
3783+
intnn_info;/* NOT NULL info */
3784+
37753785
abs_pos+=forward;
3776-
if (abs_pos<0)
3777-
{
3778-
/* out of partition */
3779-
if (isout)
3780-
*isout= true;
3781-
*isnull= true;
3782-
datum=0;
3786+
if (abs_pos<0)/* apparently out of partition */
37833787
break;
3784-
}
37853788

3786-
switch (get_notnull_info(winobj,abs_pos))
3789+
/* check NOT NULL cached info */
3790+
nn_info=get_notnull_info(winobj,abs_pos);
3791+
if (nn_info==NN_NOTNULL)/* this row is known to be NOT NULL */
3792+
notnull_offset++;
3793+
3794+
elseif (nn_info==NN_NULL)/* this row is known to be NULL */
3795+
continue;/* keep on moving forward or backward */
3796+
3797+
else/* need to check NULL or not */
37873798
{
3788-
caseNN_NOTNULL:/* this row is known to be NOT NULL */
3789-
notnull_offset++;
3790-
if (notnull_offset >=notnull_relpos)
3791-
{
3792-
/* prepare to exit this loop */
3793-
datum=gettuple_eval_partition(winobj,argno,
3794-
abs_pos,isnull,isout);
3795-
}
3796-
break;
3797-
caseNN_NULL:/* this row is known to be NULL */
3798-
if (isout)
3799-
*isout= false;
3800-
*isnull= true;
3801-
datum=0;
3802-
break;
3803-
default:/* need to check NULL or not */
3804-
datum=gettuple_eval_partition(winobj,argno,
3805-
abs_pos,isnull,isout);
3806-
if (*isout)/* out of partition? */
3807-
returndatum;
3808-
3809-
if (!*isnull)
3810-
notnull_offset++;
3811-
/* record the row status */
3812-
put_notnull_info(winobj,abs_pos,*isnull);
3799+
/* get tupple and evaluate in a partition */
3800+
datum=gettuple_eval_partition(winobj,argno,
3801+
abs_pos,isnull,&myisout);
3802+
if (myisout)/* out of partition? */
38133803
break;
3804+
if (!*isnull)
3805+
notnull_offset++;
3806+
/* record the row status */
3807+
put_notnull_info(winobj,abs_pos,*isnull);
38143808
}
38153809
}while (notnull_offset<notnull_relpos);
38163810

3817-
if (!*isout&&set_mark)
3811+
/* get tupple and evaluate in a partition */
3812+
datum=gettuple_eval_partition(winobj,argno,
3813+
abs_pos,isnull,&myisout);
3814+
if (!myisout&&set_mark)
38183815
WinSetMarkPosition(winobj,abs_pos);
3816+
if (isout)
3817+
*isout=myisout;
38193818

38203819
returndatum;
38213820
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp