Skip to content

Commit 898f54f

Browse files
authored
Merge pull request #95 from Alexhuszagh/ptr
Fixes #94, with unspecified behavior in pointer comparisons.
2 parents fe1ce58 + 3e74ed3 commit 898f54f

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

include/fast_float/ascii_number.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <cctype>
66
#include <cstdint>
77
#include <cstring>
8+
#include <iterator>
89

910
#include "float_common.h"
1011

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

0 commit comments

Comments
 (0)