File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -2299,6 +2299,12 @@ class parser
2299
2299
public:
2300
2300
auto is_within_function_body (source_position p) const
2301
2301
{
2302
+ // Short circuit the empty case, so that the rest of the function
2303
+ // can unconditionally decrement any non-.begin() iterator once
2304
+ if (function_body_extents.empty ()) {
2305
+ return false ;
2306
+ }
2307
+
2302
2308
// Ensure we are sorted
2303
2309
if (!is_function_body_extents_sorted) {
2304
2310
std::sort (
@@ -2308,18 +2314,22 @@ class parser
2308
2314
is_function_body_extents_sorted = true ;
2309
2315
}
2310
2316
2311
- // Find the first entry that is beyond pos
2317
+ // Find the first entry that is beyond pos, and back up one to
2318
+ // the last that could be a match; this also ensures iter is
2319
+ // dereferenceable, not .end()
2312
2320
auto iter = std::lower_bound (
2313
2321
function_body_extents.begin (),
2314
2322
function_body_extents.end (),
2315
2323
p.lineno +1
2316
2324
);
2325
+ if (iter != function_body_extents.begin ()) {
2326
+ --iter;
2327
+ }
2317
2328
2318
2329
// Now go backwards through the preceding entries until
2319
2330
// one includes pos or we move before pos
2320
2331
while (
2321
- iter != function_body_extents.end ()
2322
- && iter->last >= p.lineno
2332
+ iter->last >= p.lineno
2323
2333
)
2324
2334
{
2325
2335
if (
You can’t perform that action at this time.
0 commit comments