files: do not let a stray CR in a DOS file trigger Mac format

Only when a CR is seen before any LF, and the CR is not followed
by a LF, should this CR be interpreted as a line separator.  And
only then the file should be reported as being in Mac format --
as long as --noconvert is not used.

This fixes https://savannah.gnu.org/bugs/?58357.

Bug existed since at least version 2.0.6.
This commit is contained in:
Benno Schulenberg 2020-05-12 16:39:18 +02:00
parent 0a1817e893
commit ac0f2c9485

View File

@ -683,7 +683,7 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable)
if ((num_lines == 0 || format != 0) && !ISSET(NO_CONVERT) &&
len > 0 && buf[len - 1] == '\r')
format |= 1;
} else if ((num_lines == 0 || format != 0) && !ISSET(NO_CONVERT) &&
} else if ((num_lines == 0 || format == 2) && !ISSET(NO_CONVERT) &&
len > 0 && buf[len - 1] == '\r') {
format |= 2;
#endif