]> git.ipfire.org Git - thirdparty/rrdtool-1.x.git/commitdiff
cleanup rrd_strtodbl calls
authorTobias Oetiker <tobi@oetiker.ch>
Wed, 20 Aug 2014 14:00:17 +0000 (16:00 +0200)
committerTobias Oetiker <tobi@oetiker.ch>
Wed, 20 Aug 2014 14:00:17 +0000 (16:00 +0200)
doc/librrd.pod
src/rrd_daemon.c
src/rrd_graph.c
src/rrd_graph_helper.c
src/rrd_restore.c
src/rrd_strtod.c
src/rrd_tune.c
src/rrd_update.c

index f6ecba092aeedc119d1b0898e87efe54d21679ff..0e5bdf72631d044b793ac7da1ebefdad19140e98 100644 (file)
@@ -82,6 +82,11 @@ values supplied to the fetch function. If the values are the same, the previous
 Generates random numbers just like random().  This further ensures that
 the random number generator is seeded exactly once per process.
 
+=item B<rrd_strtodbl>
+
+an rrd aware string to double convertor which sets rrd_error in if there is a problem
+and uses the return code exclusively for conversion status reporting.
+
 =item B<rrd_strtod>
 
 works like normal strtod, but it is locale independent (and thread safe)
index ef4ec1070f440c357b50a8661ecd3b2216915873..6ff840033eda8d96f19d75d900595cd718c0f933 100644 (file)
@@ -1512,7 +1512,7 @@ static int handle_request_update (HANDLER_PROTO) /* {{{ */
 
     /* make sure update time is always moving forward. We use double here since
        update does support subsecond precision for timestamps ... */
-    if ( ( rrd_strtodbl( value, &eostamp, &stamp, "error while parsing time stamp" ) != 1 ) || *eostamp != ':')
+    if ( ( rrd_strtodbl( value, &eostamp, &stamp, NULL) != 1 ) || *eostamp != ':')
     {
       pthread_mutex_unlock(&cache_lock);
       return send_response(sock, RESP_ERR,
index db1228184dfd040fc8d9b5b0cd4647c010581c71..b501a450bb561d4f0824a275803694c871c65203 100644 (file)
@@ -4583,7 +4583,8 @@ void rrd_graph_options(
             im->forceleftspace = 1;
             break;
         case 'T':
-            rrd_strtodbl(optarg, 0, &(im->tabwidth), "Function rrd_graph_options, option 'T'");
+            if (rrd_strtodbl(optarg, 0, &(im->tabwidth), "option -T") != 2)
+                return;
             break;
         case 'S':
             im->step = atoi(optarg);
@@ -4652,7 +4653,9 @@ void rrd_graph_options(
                 break;
             };
             if (sscanf(optarg, "%[-0-9.e+]:%d", double_str , &im->ylabfact) == 2) {
-                rrd_strtodbl( double_str, 0, &(im->ygridstep), "Function rrd_graph_options, option 'y'");
+                if (rrd_strtodbl( double_str, 0, &(im->ygridstep), "option -y") != 2){
+                    return;
+                }
                 if (im->ygridstep <= 0) {
                     rrd_set_error("grid step must be > 0");
                     return;
@@ -4673,10 +4676,11 @@ void rrd_graph_options(
                       "%[-0-9.e+]:%[-0-9.e+]",
                       double_str,
                       double_str2 ) != 2) {
-                rrd_strtodbl( double_str, 0, &(im->grid_dash_on), "Function rrd_graph_options, option 1008");
-                rrd_strtodbl( double_str2, 0, &(im->grid_dash_off), "Function rrd_graph_options, option 1008");
-                rrd_set_error("expected grid-dash format float:float");
-                return;
+                if ( rrd_strtodbl( double_str, 0, &(im->grid_dash_on),NULL) !=2 
+                     || rrd_strtodbl( double_str2, 0, &(im->grid_dash_off), NULL) != 2 ){
+                    rrd_set_error("expected grid-dash format float:float");
+                    return;
+                }
             }
             break;   
         case 1009: /* enable dynamic labels */
@@ -4690,9 +4694,9 @@ void rrd_graph_options(
             if(sscanf(optarg,
                       "%[-0-9.e+]:%[-0-9.e+]",
                       double_str,
-                      double_str2 ) == 2) {
-                rrd_strtodbl( double_str, 0, &(im->second_axis_scale), "Function rrd_graph_options, option 1002");
-                rrd_strtodbl( double_str2, 0, &(im->second_axis_shift), "Function rrd_graph_options, option 1002");
+                      double_str2 ) == 2
+                && rrd_strtodbl( double_str, 0, &(im->second_axis_scale),NULL) == 2
+                && rrd_strtodbl( double_str2, 0, &(im->second_axis_shift),NULL) == 2){
                 if(im->second_axis_scale==0){
                     rrd_set_error("the second_axis_scale  must not be 0");
                     return;
@@ -4739,10 +4743,14 @@ void rrd_graph_options(
             }
             break;
         case 'u':
-            rrd_strtodbl(optarg, 0, &(im->maxval), "Function rrd_graph_options, option 'u'");
+            if (rrd_strtodbl(optarg, 0, &(im->maxval), "option -u") != 2){
+                return;
+            }
             break;
         case 'l':
-            rrd_strtodbl(optarg, 0, &(im->minval), "Function rrd_graph_options, option 'l'");
+            if (rrd_strtodbl(optarg, 0, &(im->minval), "option -l") != 2){
+                return;
+            }
             break;
         case 'b':
             im->base = atol(optarg);
@@ -4854,8 +4862,8 @@ void rrd_graph_options(
             double    size = 1;
             int       end;
 
-            if (sscanf(optarg, "%10[A-Z]:%[-0-9.e+]%n", prop, double_str, &end) >= 2) {
-                rrd_strtodbl( double_str, 0, &size, "Function rrd_graph_options, option 'n'" );
+            if (sscanf(optarg, "%10[A-Z]:%[-0-9.e+]%n", prop, double_str, &end) >= 2
+                && rrd_strtodbl( double_str, 0, &size, NULL) == 2) {
                 int       sindex, propidx;
 
                 if ((sindex = text_prop_conv(prop)) != -1) {
@@ -4890,7 +4898,9 @@ void rrd_graph_options(
             break;
         }
         case 'm':
-            rrd_strtodbl(optarg, 0, &(im->zoom), "Function rrd_graph_options, option 'm'");
+            if (rrd_strtodbl(optarg, 0, &(im->zoom), "option -m") != 2){
+                return;
+            }
             if (im->zoom <= 0.0) {
                 rrd_set_error("zoom factor must be > 0");
                 return;
@@ -5162,8 +5172,7 @@ int vdef_parse(
 
     n = 0;
     sscanf(str, "%20[-0-9.e+],%29[A-Z]%n", double_str, func, &n);
-    if ( rrd_strtodbl( str, NULL, &param, "Function vdef_parse" ) != 2){
-        rrd_clear_error();
+    if ( rrd_strtodbl( str, NULL, &param, NULL) != 2 ){
         n = 0;
         sscanf(str, "%29[A-Z]%n", func, &n);
         if (n == (int) strlen(str)) {   /* matched */
index 29325241723b58f359aff521ca9e259c9b07ad95..1b10f90334aba16e319a29476dd2f17289e0bbb5 100644 (file)
@@ -144,21 +144,23 @@ int getDouble(const char* v, double *val,char**extra) {
   unsigned int strtod_ret;
   *extra=NULL;
 
-  if( rrd_strtodbl( v, extra, val, "Function getDouble" ) != 2 ) {
-    return -1;
-  }
-
-  strtod_ret = rrd_strtodbl( v, extra, val, "Function getDouble" );
+  strtod_ret = rrd_strtodbl( v, extra, val, NULL);
 
   /* see rrd_strtodbl's return values for more infromation */
-  if( strtod_ret == 0 )
-    return -1;
-  else if( strtod_ret == 1 )
-    return 1;
-  else if( strtod_ret == 2 )
-    return 0;
-  else
-    return -2;
+  switch (rrd_strtodbl( v, extra, val, NULL)){
+    case 0:
+        return -1;
+        break;
+    case 1:
+        return 1;
+        break;
+    case 2:
+        return 0;
+        break;
+    default:
+        return -2;
+        break;
+  }
 }
 
 int addToArguments(parsedargs_t* pa, char*key, char*value, int cnt) {
index ae5772b1df784c6f609bcdffdb3093f16ad975b3..8fa5c1b6f1c67943cb5879a22b348554547837c7 100644 (file)
@@ -329,7 +329,7 @@ static int get_xml_double(
             xmlFree(text);
             return 0;            
         }        
-        if ( rrd_strtodbl((char *)text,NULL, &temp, "Function xml_get_double") != 2 ){
+        if ( rrd_strtodbl((char *)text,NULL, &temp, NULL) != 2 ){
             rrd_set_error("ling %d: get_xml_double from '%s' %s",
                           xmlTextReaderGetParserLineNumber(reader),
                           text,rrd_strerror(errno));
index 98aef39e5e0d3108fd3d71b1cccd9267ab5abf61..b613458971c057f0f3a96ebe92add2aae1c6028a 100644 (file)
@@ -54,19 +54,14 @@ unsigned int rrd_strtodbl
     if ( local_endptr == (char *)str ) {
         /* no conversion has been done */
         /* for inputs like "abcdj", i.e. no number at all */
-        if( error == NULL ) {
-            rrd_set_error("Cannot convert %s to float", str);
-        } else {
+        if( error ) {
             rrd_set_error("%s - Cannot convert %s to float", error, str);
         }
         return 0;
     } else if( local_endptr[0] != '\0' ) {
         /* conversion has been done, but whole string is not a number */
         /* for inputs like "33.343djdjk" */
-        if( error == NULL ) {
-            rrd_set_error("Converted %s to %lf, but cannot convert %s",
-                           str, *dbl, local_endptr);
-        } else {
+        if( error ) {
             rrd_set_error("%s - Converted %s to %lf, but cannot convert %s",
                            error, str, *dbl, local_endptr);
         }
@@ -77,11 +72,9 @@ unsigned int rrd_strtodbl
         return 2;
     } else {
       /* just to be safe */
-        if( error == NULL )
-            rrd_set_error("Internal error. Something is seriously wrong '%s'", str);
-        else
+        if( error ) {
             rrd_set_error("%s - Internal error. Something is seriously wrong '%s'",error, str);
-
+        }
         return 3;
     }
 }
index 25831c9b5b19978734f7605ed20f107864a929b5..ad41d73f17f2a9483c119ce7c841355a5d187711 100644 (file)
@@ -209,7 +209,7 @@ int rrd_tune(
         case 'i':
             matches = sscanf(optarg, DS_NAM_FMT ":%[-0-9.e+]", ds_nam, double_str);
             if( matches >= 1 ) {
-                strtod_ret_val = rrd_strtodbl( double_str, 0, &min, "Function rrd_tune, option i" );
+                strtod_ret_val = rrd_strtodbl( double_str, NULL, &min, NULL );
             }
 
             if ((matches < 1) || (strtod_ret_val != 2)) {
@@ -229,7 +229,7 @@ int rrd_tune(
         case 'a':
             matches = sscanf(optarg, DS_NAM_FMT ":%[-0-9.e+]", ds_nam, double_str);
             if( matches >= 1 ) {
-                strtod_ret_val = rrd_strtodbl( double_str, 0, &max, "Function rrd_tune, option i" );
+                strtod_ret_val = rrd_strtodbl( double_str, NULL, &max, NULL );
             }
 
             if ((matches < 1 ) || (strtod_ret_val != 2)) {
@@ -430,7 +430,7 @@ int set_hwarg(
     signed short rra_idx = -1;
     unsigned int strtod_ret_val;
 
-    strtod_ret_val = rrd_strtodbl(arg, 0, &param, "Error while parsing Holt-Winters parameter");
+    strtod_ret_val = rrd_strtodbl(arg, NULL, &param, NULL);
     /* read the value */
     if ((strtod_ret_val == 1 || strtod_ret_val == 2 ) &&
          (param <= 0.0 || param >= 1.0) ) {
@@ -469,7 +469,7 @@ int set_hwsmootharg(
     unsigned int strtod_ret_val;
 
     /* read the value */
-    strtod_ret_val = rrd_strtodbl(arg, 0, &param, "Error while parsing Holt-Winters parameter, function set_hesmootharg");
+    strtod_ret_val = rrd_strtodbl(arg, NULL, &param, NULL);
     /* in order to avoid smoothing of SEASONAL or DEVSEASONAL, we need to 
      * the 0.0 value*/
     if ( (strtod_ret_val == 1 || strtod_ret_val == 2 ) &&
@@ -507,7 +507,7 @@ int set_deltaarg(
     signed short rra_idx = -1;
     unsigned int strtod_ret_val;
 
-    strtod_ret_val = rrd_strtodbl(arg, 0, &param, "Function set_deltaarg" );
+    strtod_ret_val = rrd_strtodbl(arg, NULL, &param, NULL);
     if ((strtod_ret_val == 1 || strtod_ret_val == 2) &&
          param < 0.1) {
         rrd_set_error("Parameter specified is too small");
index 588c34608fe47f2489dc9804fcae18dba8256d6f..262dc3bdf2fd14dececf7141d4b523cac2266d1c 100644 (file)
@@ -1317,7 +1317,7 @@ static int get_time_from_reading(
         *current_time = tmp_time.tv_sec;
         *current_time_usec = tmp_time.tv_usec;
     } else {
-        if ( rrd_strtodbl( updvals[0], 0, &tmp, "error while parsing time in get_time_from_reading") != 2) {
+        if ( rrd_strtodbl( updvals[0], NULL, &tmp, "error while parsing time in get_time_from_reading") != 2) {
             return -1;
         };
         if (tmp < 0.0){
@@ -1422,13 +1422,13 @@ static int update_pdp_prep(
                 }
                 break;
             case DST_ABSOLUTE:
-                if( rrd_strtodbl(updvals[ds_idx + 1], 0, &pdp_new[ds_idx], "Function update_pdp_prep, case DST_ABSOLUTE" ) != 2 ) {
+                if( rrd_strtodbl(updvals[ds_idx + 1], NULL, &pdp_new[ds_idx], "Function update_pdp_prep, case DST_ABSOLUTE" ) != 2 ) {
                     return -1;
                 }
                 rate = pdp_new[ds_idx] / interval;
                 break;
             case DST_GAUGE:
-                if( rrd_strtodbl( updvals[ds_idx + 1], 0, &tmp, "Function update_pdp_prep, case DST_GAUGE") == 2 ) {
+                if( rrd_strtodbl( updvals[ds_idx + 1], NULL, &tmp, "Function update_pdp_prep, case DST_GAUGE") == 2 ) {
                     pdp_new[ds_idx] = tmp * interval;
                 } else {
                     return -1;