commit e7bc965790eabc4fcc1fa31c6d260b70740e75c6
parent bc749a762177ed5c0f5f7dd9cbb46ec51652667e
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 24 Feb 2016 10:05:45 +0100
Fix a invalid memory read
If the phase function limit angle cannot be found, the returned pointer
is null but its pointed value was acceded.
Diffstat:
1 file changed, 13 insertions(+), 15 deletions(-)
diff --git a/src/sschiff_estimator.c b/src/sschiff_estimator.c
@@ -337,9 +337,9 @@ compute_path_length
} while(hit.distance < range[0] || self_hit(&hit_from, &hit, 1.e-6f));
if(S3D_HIT_NONE(&hit)) {
- log_error(dev,
+/* log_error(dev,
"Error in computing the radiative path length. This may be due to numerical\n"
-"imprecisions or to a geometry that does not define a closed volume.\n");
+"imprecisions or to a geometry that does not define a closed volume.\n");*/
return RES_BAD_OP;
}
@@ -571,14 +571,6 @@ phase_function_post_process
accums->differential_cross_section_cumulative[ilimit_angle].weight
/ (double)estimator->nrealisations;
- {
- struct sschiff_state state;
- get_mc_value
- (&accums->differential_cross_section[ilimit_angle],
- estimator->nrealisations,
- &state);
- }
-
/* Precompute some values to speed up Newton iterations */
arg.cos_2_angle = cos(2.0 * arg.angle);
arg.cos_angle = cos(arg.angle);
@@ -590,11 +582,12 @@ phase_function_post_process
/* Setup system functions */
func.f = NULL;
func.df = NULL;
- func.fdf = function_fdf;
+ func.fdf = function_fdf; /* Compute the function *and* its derivative */
func.n = 1; /* Number of equations */
func.params = &arg; /* System parameters */
- /* Initialise the solver */
+ /* Initialise the solver. TODO perform this in an initialisation step of a
+ * phase_function context */
gsl_vector_set(init_val, 0, 3.0); /* n */
gsl_multiroot_fdfsolver_set(solver, &func, init_val);
gsl_set_error_handler_off();
@@ -611,8 +604,8 @@ phase_function_post_process
if(status != GSL_SUCCESS) {
/* TODO enhance the error message. */
- log_error(dev, "Error in Newton estimation - GSL error: %s.\n",
- gsl_strerror(status));
+ log_error(dev, "Error in Newton estimation - GSL error: %s - %d.\n",
+ gsl_strerror(status), iter);
res = RES_BAD_OP;
goto error;
}
@@ -923,7 +916,12 @@ geometry_context_init
theta_l = sqrt(lambda_e * rcp_PI_Lc);
angle = search_lower_bound
(&theta_l, angles, nangles, sizeof(double), cmp_double);
- if(!angle || eq_eps(*angle, PI, 1.e-6)) {
+ if(!angle) {
+ log_error(dev, "Can't find a limit angle for theta = %g.\n", theta_l);
+ res = RES_BAD_ARG;
+ goto error;
+ }
+ if(eq_eps(*angle, PI, 1.e-6)) {
log_error(dev, "Invalid limit angle \"%g\".\n", *angle);
res = RES_BAD_ARG;
goto error;