[master] 7300ca4 Use the new VNUM() in the trivial cases
Poul-Henning Kamp
phk at FreeBSD.org
Tue Feb 24 00:05:15 CET 2015
commit 7300ca4c3cfc1ca3a8501a77481cf0221e05d0fb
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Mon Feb 23 22:17:04 2015 +0000
Use the new VNUM() in the trivial cases
diff --git a/bin/varnishd/mgt/mgt_param_tweak.c b/bin/varnishd/mgt/mgt_param_tweak.c
index 7d4a13f..3fe28dc 100644
--- a/bin/varnishd/mgt/mgt_param_tweak.c
+++ b/bin/varnishd/mgt/mgt_param_tweak.c
@@ -58,29 +58,25 @@ tweak_generic_double(struct vsb *vsb, volatile double *dest,
const char *arg, const char *min, const char *max, const char *fmt)
{
double u, minv = 0, maxv = 0;
- char *p;
if (arg != NULL) {
if (min != NULL) {
- p = NULL;
- minv = strtod(min, &p);
- if (*arg == '\0' || *p != '\0') {
+ minv = VNUM(min);
+ if (isnan(minv)) {
VSB_printf(vsb, "Illegal Min: %s\n", min);
return (-1);
}
}
if (max != NULL) {
- p = NULL;
- maxv = strtod(max, &p);
- if (*arg == '\0' || *p != '\0') {
+ maxv = VNUM(max);
+ if (isnan(maxv)) {
VSB_printf(vsb, "Illegal Max: %s\n", max);
return (-1);
}
}
- p = NULL;
- u = strtod(arg, &p);
- if (*arg == '\0' || *p != '\0') {
+ u = VNUM(arg);
+ if (isnan(u)) {
VSB_printf(vsb, "Not a number(%s)\n", arg);
return (-1);
}
diff --git a/bin/varnishtest/vtc.c b/bin/varnishtest/vtc.c
index c70b267..5759d38 100644
--- a/bin/varnishtest/vtc.c
+++ b/bin/varnishtest/vtc.c
@@ -43,6 +43,7 @@
#include "vtc.h"
#include "vav.h"
+#include "vnum.h"
#include "vtim.h"
#define MAX_TOKENS 200
@@ -433,7 +434,7 @@ cmd_delay(CMD_ARGS)
return;
AN(av[1]);
AZ(av[2]);
- f = strtod(av[1], NULL);
+ f = VNUM(av[1]);
vtc_log(vl, 3, "delaying %g second(s)", f);
VTIM_sleep(f);
}
diff --git a/bin/varnishtest/vtc_http.c b/bin/varnishtest/vtc_http.c
index 85c3854..ba591ae 100644
--- a/bin/varnishtest/vtc_http.c
+++ b/bin/varnishtest/vtc_http.c
@@ -31,6 +31,7 @@
#include <sys/types.h>
#include <sys/socket.h>
+#include <math.h>
#include <poll.h>
#include <stdio.h>
#include <stdlib.h>
@@ -41,6 +42,7 @@
#include "vct.h"
#include "vgz.h"
+#include "vnum.h"
#include "vre.h"
#include "vtcp.h"
@@ -272,13 +274,13 @@ cmd_http_expect(CMD_ARGS)
// fail inequality comparisons if either side is undef'ed
retval = 0;
} else if (!strcmp(cmp, "<")) {
- retval = strtod(lhs, NULL) < strtod(rhs, NULL);
+ retval = isless(VNUM(lhs), VNUM(rhs));
} else if (!strcmp(cmp, ">")) {
- retval = strtod(lhs, NULL) > strtod(rhs, NULL);
+ retval = isgreater(VNUM(lhs), VNUM(rhs));
} else if (!strcmp(cmp, "<=")) {
- retval = strtod(lhs, NULL) <= strtod(rhs, NULL);
+ retval = islessequal(VNUM(lhs), VNUM(rhs));
} else if (!strcmp(cmp, ">=")) {
- retval = strtod(lhs, NULL) >= strtod(rhs, NULL);
+ retval = isgreaterequal(VNUM(lhs), VNUM(rhs));
}
if (retval == -1)
@@ -1096,13 +1098,17 @@ static void
cmd_http_timeout(CMD_ARGS)
{
struct http *hp;
+ double d;
(void)cmd;
(void)vl;
CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC);
AN(av[1]);
AZ(av[2]);
- hp->timeout = (int)(strtod(av[1], NULL) * 1000.0);
+ d = VNUM(av[1]);
+ if (isnan(d))
+ vtc_log(vl, 0, "timeout is not a number (%s)", av[1]);
+ hp->timeout = (int)(d * 1000.0);
}
/**********************************************************************
More information about the varnish-commit
mailing list