https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98882
Jakub Jelinek <jakub at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Assignee|unassigned at gcc dot gnu.org |jakub at gcc dot gnu.org Status|NEW |ASSIGNED --- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> --- Created attachment 50086 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50086&action=edit gcc11-pr98882.patch Actually, I think it is only the assert that is problematic. If the code isn't upset of pos in certain cases being bumped to buffer->rlimit + 1 (which can happen even with the \n termination of buffers, e.g. if file ends up with backslash), then the \r handling cases are all but one about the \r being still before the limit and so either rlimit[0] will be '\n' and we can safely read it, or it will be '\r' and again we can read it (it just won't be '\n'). The harder case is backslash, after which we check for newline (ok) or cr or cr + newline. But, if rlimit > cur && rlimit[-1] == '\\', then rlimit[0] must be '\n' not '\r' (as '\r' is only added if rlimit[-1] == '\r'), so we never access rlimit[1].