aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/diff/diffreg.c
diff options
context:
space:
mode:
authorKyle Evans <kevans@FreeBSD.org>2022-12-14 01:31:21 +0000
committerKyle Evans <kevans@FreeBSD.org>2022-12-14 01:31:21 +0000
commit8bf187f35b6298b7848c5ecf45b0b714327090d9 (patch)
tree78ef86a7a38ae7b56d2f620d42993ef4c0ce8231 /usr.bin/diff/diffreg.c
parent1656007e4c83e9665bcb75914d066e29772367f0 (diff)
Diffstat (limited to 'usr.bin/diff/diffreg.c')
-rw-r--r--usr.bin/diff/diffreg.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/usr.bin/diff/diffreg.c b/usr.bin/diff/diffreg.c
index def8a4e05974..1247317951d3 100644
--- a/usr.bin/diff/diffreg.c
+++ b/usr.bin/diff/diffreg.c
@@ -1247,7 +1247,8 @@ fetch(long *f, int a, int b, FILE *lb, int ch, int oldfile, int flags)
printf(" ");
}
col = 0;
- for (j = 0, lastc = '\0'; j < nc; j++, lastc = c) {
+ for (j = 0, lastc = '\0'; j < nc && (hw == 0 || col < hw);
+ j++, lastc = c) {
c = getc(lb);
if (flags & D_STRIPCR && c == '\r') {
if ((c = getc(lb)) == '\n')
@@ -1274,19 +1275,16 @@ fetch(long *f, int a, int b, FILE *lb, int ch, int oldfile, int flags)
if (flags & D_EXPANDTABS) {
newcol = ((col / tabsize) + 1) * tabsize;
do {
- if (diff_format == D_SIDEBYSIDE)
- j++;
printf(" ");
- } while (++col < newcol && j < nc);
+ } while (++col < newcol && col < hw);
} else {
if (diff_format == D_SIDEBYSIDE) {
- if ((j + tabsize) > nc) {
- printf("%*s", nc - j, "");
- j = col = nc;
+ if ((col + tabsize) > hw) {
+ printf("%*s", hw - col, "");
+ col = hw;
} else {
printf("\t");
col += tabsize - 1;
- j += tabsize - 1;
}
} else {
printf("\t");