--- i/src/syntax.c +++ w/src/syntax.c @@ -3192,7 +3192,11 @@ scan_sexps_forward (struct lisp_parse_state *state, while (from < end) { - if (SYNTAX_FLAGS_COMSTART_FIRST (prev_from_syntax) + INC_FROM; + code = prev_from_syntax & 0xff; + + if (from < end + && SYNTAX_FLAGS_COMSTART_FIRST (prev_from_syntax) && (c1 = FETCH_CHAR (from_byte), syntax = SYNTAX_WITH_FLAGS (c1), SYNTAX_FLAGS_COMSTART_SECOND (syntax))) @@ -3213,8 +3217,6 @@ scan_sexps_forward (struct lisp_parse_state *state, } else { - INC_FROM; - code = prev_from_syntax & 0xff; if (code == Scomment_fence) { /* Record the comment style we have entered so that only