aboutsummaryrefslogtreecommitdiff
path: root/src/proj_strtod.c
diff options
context:
space:
mode:
authorThomas Knudsen <busstoptaktik@users.noreply.github.com>2017-10-19 18:33:08 +0200
committerGitHub <noreply@github.com>2017-10-19 18:33:08 +0200
commit666c17ac7a9d3b958e5c74ed2649487cb0c9eb3f (patch)
treef3b8228373209276b01d41afce26334834fc1293 /src/proj_strtod.c
parent6b1880383695096a7e8e92983b6f916ad00b2d42 (diff)
downloadPROJ-666c17ac7a9d3b958e5c74ed2649487cb0c9eb3f.tar.gz
PROJ-666c17ac7a9d3b958e5c74ed2649487cb0c9eb3f.zip
Teach proj_strtod to understand corner cases 0 and 0. (#611)
Diffstat (limited to 'src/proj_strtod.c')
-rw-r--r--src/proj_strtod.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/proj_strtod.c b/src/proj_strtod.c
index aa2211f5..42b7691d 100644
--- a/src/proj_strtod.c
+++ b/src/proj_strtod.c
@@ -86,6 +86,7 @@ Thomas Knudsen, thokn@sdfe.dk, 2017-01-17/2017-09-18
***********************************************************************/
+#include <stdio.h> /* for strchr */
#include <string.h> /* for strchr */
#include <errno.h>
#include <ctype.h>
@@ -141,10 +142,14 @@ double proj_strtod(const char *str, char **endptr) {
return HUGE_VAL;
}
- /* skip prefixed zeros */
+ /* skip prefixed zeros before '.' */
while ('0'==*p || '_'==*p)
p++;
+ /* zero? */
+ if (0==*p || 0==strchr ("0123456789eE.", *p))
+ return 0;
+
/* Now expect a (potentially zero-length) string of digits */
while (isdigit(*p) || ('_'==*p)) {
if ('_'==*p) {
@@ -171,8 +176,11 @@ double proj_strtod(const char *str, char **endptr) {
}
/* if the next character is nonnumeric, we have reached the end */
- if (0==strchr ("0123456789eE+-", *p))
+ if (0==*p || 0==strchr ("0123456789eE+-", *p)) {
+ if (endptr)
+ *endptr = p;
return integral_part;
+ }
while (isdigit(*p) || '_'==*p) {
/* Don't let pathologically long fractions destroy precision */
@@ -244,10 +252,10 @@ double proj_strtod(const char *str, char **endptr) {
}
if ((exponent < DBL_MIN_EXP) || (exponent > DBL_MAX_EXP)) {
- errno = ERANGE;
- if (endptr)
- *endptr = p;
- return HUGE_VAL;
+ errno = ERANGE;
+ if (endptr)
+ *endptr = p;
+ return HUGE_VAL;
}
/* on some platforms pow() is very slow - so don't call it if exponent==0 */
@@ -260,15 +268,15 @@ double proj_strtod(const char *str, char **endptr) {
if (endptr)
*endptr = p;
-
return number;
}
double proj_atof(const char *str) {
- return proj_strtod(str, (void *) 0);
+ return proj_strtod(str, (void *) 0);
}
#ifdef TEST
+#include <stdio.h>
#include <string.h>
int main (int argc, char **argv) {