Skip to content

Commit 90d9697

Browse files
committed
arg_reader: Add check if range becomes discontiguous
A basic_scan_file_buffer, when it has buffering, it can become discontiguous while moving forward when executing ranges::next(range.begin(), ranges::distance(crange.begin(), it)). For that reason, we add a fallback in case this happened.
1 parent b9f9249 commit 90d9697

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

src/scn/impl.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5913,8 +5913,12 @@ struct default_arg_reader {
59135913
}
59145914
auto crange = get_as_contiguous(range);
59155915
SCN_TRY(it, impl(rd, crange, value));
5916-
return ranges::next(range.begin(),
5917-
ranges::distance(crange.begin(), it));
5916+
auto result = ranges::next(range.begin(),
5917+
ranges::distance(crange.begin(), it));
5918+
if (SCN_UNLIKELY(!is_segment_contiguous(range))) {
5919+
return impl(rd, range, value);
5920+
}
5921+
return result;
59185922
}
59195923
else {
59205924
SCN_EXPECT(false);
@@ -6233,8 +6237,12 @@ struct arg_reader {
62336237

62346238
auto crange = get_as_contiguous(range);
62356239
SCN_TRY(it, impl(rd, crange, value));
6236-
return ranges::next(range.begin(),
6237-
ranges::distance(crange.begin(), it));
6240+
auto result = ranges::next(range.begin(),
6241+
ranges::distance(crange.begin(), it));
6242+
if (SCN_UNLIKELY(!is_segment_contiguous(range))) {
6243+
return impl(rd, range, value);
6244+
}
6245+
return result;
62386246
}
62396247
else {
62406248
SCN_EXPECT(false);

0 commit comments

Comments
 (0)