Handle non-power-of-two tab sizes in expand(1)

This commit is contained in:
Brandon Mulcahy 2014-12-04 17:04:48 -05:00 committed by sin
parent 1150a5cbc9
commit 5214191155
1 changed files with 3 additions and 1 deletions

View File

@ -28,6 +28,8 @@ main(int argc, char *argv[])
break; break;
case 't': case 't':
tabstop = estrtol(EARGF(usage()), 0); tabstop = estrtol(EARGF(usage()), 0);
if (!tabstop)
eprintf("tab size cannot be zero\n");
break; break;
default: default:
usage(); usage();
@ -66,7 +68,7 @@ expand(const char *file, FILE *fp, int tabstop)
do { do {
col++; col++;
putchar(' '); putchar(' ');
} while (col & (tabstop - 1)); } while (col % tabstop);
} else { } else {
putchar('\t'); putchar('\t');
col += tabstop - col % tabstop; col += tabstop - col % tabstop;