diff --git a/Makefile b/Makefile index 87705a4..77cd588 100644 --- a/Makefile +++ b/Makefile @@ -77,9 +77,9 @@ test: gen_data psql q3c_test -c 'ANALYZE test_pm1' psql q3c_test -c 'ANALYZE test_small' mkdir -p results - cat sql/ang2ipix.sql | psql q3c_test > results/ang2ipix.out + cat sql/ang2ipix.sql | psql q3c_test > results/ang2ipix.out 2>&1 diff results/ang2ipix.out expected/ang2ipix.expected - cat sql/cone.sql | psql q3c_test > results/cone.out + cat sql/cone.sql | psql q3c_test > results/cone.out 2>&1 diff results/cone.out expected/cone.expected cat sql/cone_join_rev.sql | psql q3c_test > results/cone.out diff results/cone.out expected/cone.expected @@ -99,7 +99,7 @@ test: gen_data diff results/poly1.out expected/poly.expected cat sql/version.sql | psql q3c_test > results/version.out diff results/version.out expected/version.expected - cat sql/area.sql | psql q3c_test > results/area.out + cat sql/area.sql | psql q3c_test > results/area.out 2>&1 diff results/area.out expected/area.expected dropdb q3c_test createdb q3c_test diff --git a/common.h b/common.h index 844a227..2992142 100644 --- a/common.h +++ b/common.h @@ -46,6 +46,14 @@ typedef int64 q3c_ipix_t; #endif /* Q3C_IPIX_FMT */ +#ifndef Q3C_MAX_IPIX +#define Q3C_MAX_IPIX ( (((q3c_ipix_t)1<<60)-1) + ((q3c_ipix_t)1<<60) + ((q3c_ipix_t)1<<62)) +/* This is maximum allowed ipix value +101 + 1111111111111....111 + 60 ones + */ +#endif /* Q3C_MAX_IPIX */ + /* If You have not specified the Q3C_LONG_DOUBLE macro then we will use simple double functions */ diff --git a/expected/ang2ipix.expected b/expected/ang2ipix.expected index 02f0475..3290f79 100644 --- a/expected/ang2ipix.expected +++ b/expected/ang2ipix.expected @@ -118,3 +118,9 @@ 1000000 (1 row) + q3c_ipix2ang +------------------------ + {315,35.2643897079092} +(1 row) + +ERROR: Invalid ipix value diff --git a/expected/area.expected b/expected/area.expected index 3dfd737..f48b8a0 100644 --- a/expected/area.expected +++ b/expected/area.expected @@ -3,3 +3,7 @@ t (1 row) +ERROR: Invalid depth. It should be less than 31. +ERROR: Invalid depth. It should be greater than 0. +ERROR: Invalid ipix value +ERROR: Invalid ipix value diff --git a/q3c.c b/q3c.c index 90e98df..ceaa6a7 100644 --- a/q3c.c +++ b/q3c.c @@ -274,7 +274,11 @@ Datum pgq3c_ipix2ang(PG_FUNCTION_ARGS) char typalign; ArrayType *result; ipix = PG_GETARG_INT64(0); + if ((ipix < 0) || (ipix > Q3C_MAX_IPIX)) + { + elog(ERROR, "Invalid ipix value"); + } q3c_ipix2ang(&hprm, ipix, &ra, &dec); data = ( Datum *) palloc(sizeof(Datum) * 2); @@ -310,6 +314,14 @@ Datum pgq3c_pixarea(PG_FUNCTION_ARGS) { elog(ERROR, "Invalid depth. It should be less than 31."); } + if (ipix < 0) + { + elog(ERROR, "Invalid ipix value"); + } + if (ipix > Q3C_MAX_IPIX) + { + elog(ERROR, "Invalid ipix value"); + } res = q3c_pixarea(&hprm, ipix, depth); diff --git a/sql/ang2ipix.sql b/sql/ang2ipix.sql index 26e9f90..c14da25 100644 --- a/sql/ang2ipix.sql +++ b/sql/ang2ipix.sql @@ -22,3 +22,5 @@ select q3c_dist_pm(0,0,3600000,0,0,0,90,0,90)<1e-9; select q3c_dist_pm(0,0,0,3600000,0,0,0,90,90)<1e-9; select sum((q3c_ang2ipix(((q3c_ipix2ang(q3c_ang2ipix(ra,dec)))[1]),(q3c_ipix2ang(q3c_ang2ipix(ra,dec)))[2])=q3c_ang2ipix(ra,dec))::int) from test; select sum((q3c_ang2ipix(ra::real,dec::real) = q3c_ang2ipix( (ra::real)::double precision, (dec::real)::double precision))::int) from test; +select q3c_ipix2ang(0); +select q3c_ipix2ang(-1); diff --git a/sql/area.sql b/sql/area.sql index de1ec1b..32a734b 100644 --- a/sql/area.sql +++ b/sql/area.sql @@ -1 +1,6 @@ select 6*q3c_pixarea(0,30)/pi()/4. between 0.99999 and 1.00001; +select q3c_pixarea(10,31); +select q3c_pixarea(10,0); +select q3c_pixarea(-1,4); +select q3c_pixarea(6917529027641081856,4); +