Skip to content

Commit ba0add5

Browse files
committed
Check for NULL jd_tdb[2] in solarsystem_hp() variants.
1 parent e724c11 commit ba0add5

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

src/solsys1.c

+4
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ short solarsystem(double jd_tdb, short body, short origin, double *position, dou
172172
}
173173

174174
short solarsystem_hp(const double jd_tdb[2], short body, short origin, double *position, double *velocity) {
175+
if(!jd_tdb) {
176+
errno = EINVAL;
177+
return -1;
178+
}
175179
return planet_eph_manager_hp(jd_tdb, body, origin, position, velocity);
176180
}
177181
#endif

src/solsys2.c

+5
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,11 @@ short planet_jplint_hp(const double jd_tdb[2], enum novas_planet body, enum nova
176176
double posvel[6] = { };
177177
int i;
178178

179+
if(!jd_tdb) {
180+
errno = EINVAL;
181+
return -1;
182+
}
183+
179184
// Perform sanity checks on the input body and origin.
180185
if((body < NOVAS_MERCURY) || (body > NOVAS_MOON)) {
181186
errno = EINVAL;

src/solsys3.c

+5
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,11 @@ short earth_sun_calc(double jd_tdb, enum novas_planet body, enum novas_origin or
292292
short earth_sun_calc_hp(const double jd_tdb[2], enum novas_planet body, enum novas_origin origin, double *position,
293293
double *velocity) {
294294

295+
if(!jd_tdb) {
296+
errno = EINVAL;
297+
return -1;
298+
}
299+
295300
int error = earth_sun_calc(jd_tdb[0] + jd_tdb[1], body, origin, position, velocity);
296301
if(error)
297302
return error;

test/src/test-errors.c

+17
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,22 @@ static int test_earth_sun_calc() {
775775
return n;
776776
}
777777

778+
static int test_earth_sun_calc_hp() {
779+
double p[3], v[3], tdb2[2] = { NOVAS_JD_J2000 };
780+
int n = 0;
781+
782+
enable_earth_sun_hp(1);
783+
784+
if(check("earth_sun_calc_hp:tdb", -1, earth_sun_calc_hp(NULL, NOVAS_SUN, NOVAS_BARYCENTER, p, v))) n++;
785+
if(check("earth_sun_calc_hp:pos", -1, earth_sun_calc_hp(tdb2, NOVAS_SUN, NOVAS_BARYCENTER, NULL, v))) n++;
786+
if(check("earth_sun_calc_hp:vel", -1, earth_sun_calc_hp(tdb2, NOVAS_SUN, NOVAS_BARYCENTER, p, NULL))) n++;
787+
if(check("earth_sun_calc_hp:number", 2, earth_sun_calc_hp(tdb2, NOVAS_JUPITER, NOVAS_BARYCENTER, p, v))) n++;
788+
789+
enable_earth_sun_hp(0);
790+
791+
return n;
792+
}
793+
778794
static int test_sun_eph() {
779795
extern int sun_eph(double jd, double *ra, double *dec, double *dis);
780796

@@ -873,6 +889,7 @@ int main() {
873889
if(test_grav_def()) n++;
874890

875891
if(test_earth_sun_calc()) n++;
892+
if(test_earth_sun_calc_hp()) n++;
876893
if(test_sun_eph()) n++;
877894

878895
if(n) fprintf(stderr, " -- FAILED %d tests\n", n);

0 commit comments

Comments
 (0)