Page MenuHomeFreeBSD
Paste P516

bug in diff
ActivePublic

Authored by pstef on Aug 22 2021, 10:00 AM.
Tags
None
Referenced Files
F27432093: bug in diff
Aug 22 2021, 10:00 AM
Subscribers
None
pstef@thinkpad:/usr/src/usr.bin/diff3/tests $ gdiff --strip-trailing-cr 1cr.txt 2.txt | cat -v
3c3
< and a few typ0s to fix
---
> and a few typos to fix
4a5
> New line
pstef@thinkpad:/usr/src/usr.bin/diff3/tests $ diff --strip-trailing-cr 1cr.txt 2.txt | cat -v
3c3
< and a few typ0s to fix^M
---
> and a few typos to fix
4a5
> New line

Event Timeline

pstef created this object in space S1 Global.
diff --git a/usr.bin/diff/diffreg.c b/usr.bin/diff/diffreg.c
index 651ec88df90..113b7b62125 100644
--- a/usr.bin/diff/diffreg.c
+++ b/usr.bin/diff/diffreg.c
@@ -1273,7 +1273,16 @@ fetch(long *f, int a, int b, FILE *lb, int ch, int oldfile, int flags)
                }
                col = 0;
                for (j = 0, lastc = '\0'; j < nc; j++, lastc = c) {
-                       if ((c = getc(lb)) == EOF) {
+                       c = getc(lb);
+                       if (flags & D_STRIPCR && c == '\r') {
+                               if ((c = getc(lb)) == '\n')
+                                       j++;
+                               else {
+                                       ungetc(c, lb);
+                                       c = '\r';
+                               }
+                       }
+                       if (c == EOF) {
                                if (diff_format == D_EDIT ||
                                    diff_format == D_REVERSE ||
                                    diff_format == D_NREVERSE)