Skip to content

Commit

Permalink
Fix #9871 by making jl_substrtod whitespace-tolerant
Browse files Browse the repository at this point in the history
  • Loading branch information
IainNZ committed Jan 15, 2015
1 parent 3f4be47 commit 130ecbb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -755,9 +755,16 @@ DLLEXPORT int jl_substrtod(char *str, size_t offset, int len, double *out)
pend = bstr+len;
}
*out = strtod_c(bstr, &p);
if ((p == bstr) || (p != pend) ||
if (p == bstr ||
(errno==ERANGE && (*out==0 || *out==HUGE_VAL || *out==-HUGE_VAL)))
err = 1;
// Deal with case where the substring might be something like "1 ",
// which is OK, and "1 X", which we don't allow.
while (p != pend) {
if (!isspace((unsigned char)*p))
return 1;
p++;
}
if (bstr != str+offset)
free(bstr);
return err;
Expand Down
8 changes: 8 additions & 0 deletions test/strings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1305,3 +1305,11 @@ for T in (ASCIIString, UTF8String, UTF16String, UTF32String)
end
end
end

# issue #9781
# float(SubString) wasn't tolerant of trailing whitespace, which was different
# to "normal" strings. This also checks we aren't being too tolerant and allowing
# any arbitrary trailing characters.
@test float("1\n") == 1.0
@test float(split("0,1\n",","))[2] == 1.0
@test_throws ArgumentError float(split("0,1 X\n",","))[2]

0 comments on commit 130ecbb

Please sign in to comment.