Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnish-cache
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
varnishcache
varnish-cache
Commits
7b048402
Commit
7b048402
authored
Feb 23, 2015
by
Poul-Henning Kamp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More strtod() -> VNUM() conversions.
Add a VNUMpfx() variant which does not barf NAN on suffixes.
parent
7300ca4c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
26 deletions
+30
-26
vnum.h
include/vnum.h
+1
-0
Makefile.am
lib/libvarnish/Makefile.am
+1
-1
vnum.c
lib/libvarnish/vnum.c
+23
-6
vmod_std_conversions.c
lib/libvmod_std/vmod_std_conversions.c
+5
-19
No files found.
include/vnum.h
View file @
7b048402
...
...
@@ -30,4 +30,5 @@
/* from libvarnish/vnum.c */
double
VNUM
(
const
char
*
p
);
double
VNUMpfx
(
const
char
*
p
,
const
char
**
e
);
const
char
*
VNUM_2bytes
(
const
char
*
p
,
uintmax_t
*
r
,
uintmax_t
rel
);
lib/libvarnish/Makefile.am
View file @
7b048402
...
...
@@ -44,7 +44,7 @@ TESTS = vnum_c_test
noinst_PROGRAMS
=
${
TESTS
}
vnum_c_test_SOURCES
=
vnum.c
vnum_c_test_SOURCES
=
vnum.c
vas.c
vnum_c_test_CFLAGS
=
-DNUM_C_TEST
-include
config.h
vnum_c_test_LDADD
=
${
LIBM
}
...
...
lib/libvarnish/vnum.c
View file @
7b048402
...
...
@@ -31,12 +31,14 @@
#include "config.h"
#include <ctype.h>
#include <errno.h>
#include <math.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "vnum.h"
#include "vas.h"
static
const
char
err_miss_num
[]
=
"Missing number"
;
static
const
char
err_invalid_num
[]
=
"Invalid number"
;
...
...
@@ -49,12 +51,15 @@ static const char err_invalid_suff[] = "Invalid suffix";
*/
double
VNUM
(
const
char
*
p
)
VNUM
pfx
(
const
char
*
p
,
const
char
**
t
)
{
intmax_t
m
=
0
,
ee
=
0
;
double
ms
=
1
.
0
;
double
es
=
1
.
0
,
e
=
1
.
0
,
ne
=
0
.
0
;
AN
(
p
);
AN
(
t
);
*
t
=
NULL
;
while
(
isspace
(
*
p
))
p
++
;
...
...
@@ -86,26 +91,38 @@ VNUM(const char *p)
while
(
isspace
(
*
p
))
p
++
;
if
(
*
p
!=
'\0'
)
return
(
nan
(
""
))
;
*
t
=
p
;
return
(
ms
*
m
*
pow
(
10
.,
e
+
es
*
ee
));
}
double
VNUM
(
const
char
*
p
)
{
const
char
*
t
;
double
r
;
r
=
VNUMpfx
(
p
,
&
t
);
if
(
t
!=
NULL
)
r
=
nan
(
""
);
return
(
r
);
}
/**********************************************************************/
const
char
*
VNUM_2bytes
(
const
char
*
p
,
uintmax_t
*
r
,
uintmax_t
rel
)
{
double
fval
;
char
*
end
;
c
onst
c
har
*
end
;
if
(
p
==
NULL
||
*
p
==
'\0'
)
return
(
err_miss_num
);
fval
=
strtod
(
p
,
&
end
);
if
(
end
==
p
||
!
isfinite
(
fval
))
fval
=
VNUMpfx
(
p
,
&
end
);
if
(
!
isfinite
(
fval
))
return
(
err_invalid_num
);
if
(
*
end
==
'\0'
)
{
if
(
end
==
NULL
)
{
*
r
=
(
uintmax_t
)
fval
;
return
(
NULL
);
}
...
...
lib/libvmod_std/vmod_std_conversions.c
View file @
7b048402
...
...
@@ -39,6 +39,7 @@
#include "cache/cache.h"
#include "vnum.h"
#include "vrt.h"
#include "vsa.h"
#include "vtim.h"
...
...
@@ -47,7 +48,7 @@
VCL_DURATION
__match_proto__
(
td_std_duration
)
vmod_duration
(
VRT_CTX
,
VCL_STRING
p
,
VCL_DURATION
d
)
{
char
*
e
;
c
onst
c
har
*
e
;
double
r
;
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
...
...
@@ -63,12 +64,9 @@ vmod_duration(VRT_CTX, VCL_STRING p, VCL_DURATION d)
e
=
NULL
;
r
=
strtod
(
p
,
&
e
);
if
(
!
isfinite
(
r
))
return
(
d
);
r
=
VNUMpfx
(
p
,
&
e
);
if
(
e
==
NULL
)
if
(
!
isfinite
(
r
)
||
e
==
NULL
)
return
(
d
);
while
(
isspace
(
*
e
))
...
...
@@ -170,7 +168,6 @@ vmod_ip(VRT_CTX, VCL_STRING s, VCL_IP d)
VCL_REAL
__match_proto__
(
td_std_real
)
vmod_real
(
VRT_CTX
,
VCL_STRING
p
,
VCL_REAL
d
)
{
char
*
e
;
double
r
;
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
...
...
@@ -178,22 +175,11 @@ vmod_real(VRT_CTX, VCL_STRING p, VCL_REAL d)
if
(
p
==
NULL
)
return
(
d
);
while
(
isspace
(
*
p
))
p
++
;
if
(
*
p
!=
'+'
&&
*
p
!=
'-'
&&
!
isdigit
(
*
p
))
return
(
d
);
e
=
NULL
;
r
=
strtod
(
p
,
&
e
);
r
=
VNUM
(
p
);
if
(
!
isfinite
(
r
))
return
(
d
);
if
(
e
==
NULL
||
*
e
!=
'\0'
)
return
(
d
);
return
(
r
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment