Skip to content

Commit

Permalink
Fixes #94, with unspecified behavior in pointer comparisons.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexhuszagh committed Aug 21, 2021
1 parent fe1ce58 commit 3e74ed3
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions include/fast_float/ascii_number.h
Expand Up @@ -5,6 +5,7 @@
#include <cctype>
#include <cstdint>
#include <cstring>
#include <iterator>

#include "float_common.h"

Expand Down Expand Up @@ -115,10 +116,10 @@ parsed_number_string parse_number_string(const char *p, const char *pend, parse_
if ((p != pend) && (*p == decimal_point)) {
++p;
// Fast approach only tested under little endian systems
if ((p + 8 <= pend) && is_made_of_eight_digits_fast(p)) {
if ((std::distance(p, pend) >= 8) && is_made_of_eight_digits_fast(p)) {
i = i * 100000000 + parse_eight_digits_unrolled(p); // in rare cases, this will overflow, but that's ok
p += 8;
if ((p + 8 <= pend) && is_made_of_eight_digits_fast(p)) {
if ((std::distance(p, pend) >= 8) && is_made_of_eight_digits_fast(p)) {
i = i * 100000000 + parse_eight_digits_unrolled(p); // in rare cases, this will overflow, but that's ok
p += 8;
}
Expand Down Expand Up @@ -254,7 +255,7 @@ fastfloat_really_inline decimal parse_decimal(const char *p, const char *pend, p
}
// We expect that this loop will often take the bulk of the running time
// because when a value has lots of digits, these digits often
while ((p + 8 <= pend) && (answer.num_digits + 8 < max_digits)) {
while ((std::distance(p, pend) >= 8) && (answer.num_digits + 8 < max_digits)) {
uint64_t val = read_u64(p);
if(! is_made_of_eight_digits_fast(val)) { break; }
// We have eight digits, process them in one go!
Expand Down

0 comments on commit 3e74ed3

Please sign in to comment.