From: Tobias Oetiker Date: Fri, 15 May 2015 01:12:38 +0000 (-0400) Subject: remove remaining atof calls X-Git-Tag: v1.5.4~39^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9656454b312efd9ff1d8c47743027cc0b80dc417;p=thirdparty%2Frrdtool-1.x.git remove remaining atof calls --- diff --git a/src/rrd_create.c b/src/rrd_create.c index 86ff3dcd..223c63ef 100644 --- a/src/rrd_create.c +++ b/src/rrd_create.c @@ -531,11 +531,13 @@ int parseRRA(const char *def, rrd_set_error("Invalid row count %s: %s", token, parsetime_error); break; default: - rra_def->par[RRA_cdp_xff_val].u_val = atof(token); - if (rra_def->par[RRA_cdp_xff_val].u_val < 0.0 - || rra_def->par[RRA_cdp_xff_val].u_val >= 1.0) - rrd_set_error + double xff; + if (rrd_strtodbl(token, NULL, &xff, NULL) != 2 + || xff < 0.0 || xff >= 1.0 ){ + rrd_set_error ("Invalid xff: must be between 0 and 1"); + } + rra_def->par[RRA_cdp_xff_val].u_val = xff; break; } break; @@ -544,18 +546,23 @@ int parseRRA(const char *def, (rra_def->cf_nam)) { case CF_HWPREDICT: case CF_MHWPREDICT: - rra_def->par[RRA_hw_alpha]. - u_val = atof(token); - if (atof(token) <= 0.0 || atof(token) >= 1.0) + double hw_alpha; + if (rrd_strtodbl(token, NULL, &hw_alpha, NULL) != 2 + || hw_alpha <= 0.0 || hw_alpha >= 1.0){ rrd_set_error ("Invalid alpha: must be between 0 and 1"); + } + rra_def->par[RRA_hw_alpha].u_val = hw_alpha; break; case CF_DEVSEASONAL: case CF_SEASONAL: - rra_def->par[RRA_seasonal_gamma].u_val = atof(token); - if (atof(token) <= 0.0 || atof(token) >= 1.0) + double gamma; + if (rrd_strtodbl(token, NULL, &gamma, NULL) != 2 + || gamma <= 0.0 || gamma >= 1.0){ rrd_set_error ("Invalid gamma: must be between 0 and 1"); + } + rra_def->par[RRA_seasonal_gamma].u_val = gamma; rra_def->par[RRA_seasonal_smooth_idx].u_cnt = hash % rra_def->row_cnt; break; @@ -584,10 +591,13 @@ int parseRRA(const char *def, switch (cf_conv(rra_def->cf_nam)) { case CF_HWPREDICT: case CF_MHWPREDICT: - rra_def->par[RRA_hw_beta].u_val = atof(token); - if (atof(token) < 0.0 || atof(token) > 1.0) + double beta; + if (rrd_strtodbl(token, NULL, &beta, NULL) != 2 + || beta < 0.0 || beta > 1.0){ rrd_set_error ("Invalid beta: must be between 0 and 1"); + } + rra_def->par[RRA_hw_beta].u_val = beta; break; case CF_DEVSEASONAL: case CF_SEASONAL: diff --git a/src/rrd_diff.c b/src/rrd_diff.c index fc356393..cc64eb96 100644 --- a/src/rrd_diff.c +++ b/src/rrd_diff.c @@ -8,6 +8,7 @@ #include #include "rrd_tool.h" +#include "rrd_strtodbl.h" double rrd_diff( char *a, @@ -83,10 +84,17 @@ double rrd_diff( c = 0; } } - result = -atof(res); - } else - result = atof(res); - + if (rrd_strtodbl(res, NULL, &result, 'expected a number') != 2){ + result = DNAN; + } + else { + result = -result; + } + } else { + if (rrd_strtodbl(res, NULL, &result, 'expected a number') != 2){ + result = DNAN; + } + } if (a_neg + b_neg == 2) /* both are negatives, reverse sign */ result = -result;