Repository: lucy-clownfish Updated Branches: refs/heads/master fa009460e -> f3bab0eec
Ensure nul-terminated arg to strtod. Inside Str_To_F64 we use strtod, which requires a nul-terminated C string argument. Now that Clownfish Strings consistently lack nul-termination, we need to copy content into a nul-terminated buffer and pass that to strtod. Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/4dab61a5 Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/4dab61a5 Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/4dab61a5 Branch: refs/heads/master Commit: 4dab61a5717135c4f60fc6d063e21870a453bb1f Parents: f5139ff Author: Marvin Humphrey <[email protected]> Authored: Mon Mar 14 16:05:23 2016 -0700 Committer: Marvin Humphrey <[email protected]> Committed: Mon Mar 14 16:05:23 2016 -0700 ---------------------------------------------------------------------- runtime/core/Clownfish/String.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/4dab61a5/runtime/core/Clownfish/String.c ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/String.c b/runtime/core/Clownfish/String.c index 7c2c0fa..ac17bad 100644 --- a/runtime/core/Clownfish/String.c +++ b/runtime/core/Clownfish/String.c @@ -263,8 +263,8 @@ Str_BaseX_To_I64_IMP(String *self, uint32_t base) { return retval; } -static double -S_safe_to_f64(String *self) { +double +Str_To_F64_IMP(String *self) { size_t amount = self->size < 511 ? self->size : 511; char buf[512]; memcpy(buf, self->ptr, amount); @@ -272,17 +272,6 @@ S_safe_to_f64(String *self) { return strtod(buf, NULL); } -double -Str_To_F64_IMP(String *self) { - char *end; - double value = strtod(self->ptr, &end); - size_t consumed = end - self->ptr; - if (consumed > self->size) { // strtod overran - value = S_safe_to_f64(self); - } - return value; -} - char* Str_To_Utf8_IMP(String *self) { char *buf = (char*)malloc(self->size + 1);
