Commits

intgr committed 7441750

Don't crash when xirr input is NULL

  • Participants
  • Parent commits 916f562

Comments (0)

Files changed (3)

 	double		amount;
 	TimestampTz	time;
 
-	/* FIXME */
-	Assert(!PG_ARGISNULL(1));
-	Assert(!PG_ARGISNULL(2));
+	if (PG_ARGISNULL(1))
+		elog(ERROR, "xirr amount input cannot be NULL");
+	if (PG_ARGISNULL(2))
+		elog(ERROR, "xirr timestamp input cannot be NULL");
 
 	if (PG_ARGISNULL(0))
 	{

File test/expected/xirr.out

      
 (1 row)
 
+SELECT xirr(NULL, '2013-01-01');
+ERROR:  xirr amount input cannot be NULL
+SELECT xirr(100, NULL);
+ERROR:  xirr timestamp input cannot be NULL
 CREATE TEMPORARY TABLE transactions AS
     SELECT -10.0::float8 amt, generate_series(timestamptz '2001-01-01', '2012-01-01', '1 day') ts
     UNION

File test/sql/xirr.sql

 SELECT xirr(amt, ts) FROM (VALUES(-100::float, '2013-01-01'::timestamptz), ('Infinity', '2013-02-01')) x(amt, ts);
 SELECT xirr(-100, '2013-01-01');
 SELECT xirr(100, '2013-01-01');
+SELECT xirr(NULL, '2013-01-01');
+SELECT xirr(100, NULL);
 
 CREATE TEMPORARY TABLE transactions AS
     SELECT -10.0::float8 amt, generate_series(timestamptz '2001-01-01', '2012-01-01', '1 day') ts