Skip to content

Commit bfeede9

Browse files
committed
Don't crash on empty statements in SQL-standard function bodies.
gram.y should discard NULL pointers (empty statements) when assembling a routine_body_stmt_list, as it does for other sorts of statement lists. Julien Rouhaud and Tom Lane, per report from Noah Misch. Discussion: https://postgr.es/m/20210606044418.GA297923@rfd.leadboat.com
1 parent 37e1cce commit bfeede9

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

src/backend/parser/gram.y

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7990,7 +7990,11 @@ opt_routine_body:
79907990
routine_body_stmt_list:
79917991
routine_body_stmt_list routine_body_stmt ';'
79927992
{
7993-
$$ = lappend($1, $2);
7993+
/* As in stmtmulti, discard empty statements */
7994+
if ($2 != NULL)
7995+
$$ = lappend($1, $2);
7996+
else
7997+
$$ = $1;
79947998
}
79957999
| /*EMPTY*/
79968000
{

src/test/regress/expected/create_function_3.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ CREATE FUNCTION functest_S_3() RETURNS boolean
267267
RETURN false;
268268
CREATE FUNCTION functest_S_3a() RETURNS boolean
269269
BEGIN ATOMIC
270-
RETURN false;
270+
;;RETURN false;;
271271
END;
272272
CREATE FUNCTION functest_S_10(a text, b date) RETURNS boolean
273273
LANGUAGE SQL

src/test/regress/sql/create_function_3.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ CREATE FUNCTION functest_S_3() RETURNS boolean
165165
RETURN false;
166166
CREATE FUNCTION functest_S_3a() RETURNS boolean
167167
BEGIN ATOMIC
168-
RETURN false;
168+
;;RETURN false;;
169169
END;
170170

171171
CREATE FUNCTION functest_S_10(a text, b date) RETURNS boolean

0 commit comments

Comments
 (0)