Don't overwrite the line buffer when we hit EOF on one of the files in comm(1)

This commit is contained in:
sin 2014-11-13 15:55:02 +00:00
parent d208659414
commit 519a4f8105
1 changed files with 6 additions and 0 deletions

6
comm.c
View File

@ -49,14 +49,20 @@ main(int argc, char *argv[])
for(;;) {
if(diff <= 0) {
lines[0][0] = '\0';
if(!nextline(lines[0], sizeof(lines[0]),
fp[0], argv[0])) {
if (lines[1][0] != '\0')
printline(1, lines[1]);
finish(1, fp[1], argv[1]);
}
}
if(diff >= 0) {
lines[1][0] = '\0';
if(!nextline(lines[1], sizeof(lines[1]),
fp[1], argv[1])) {
if (lines[0][0] != '\0')
printline(0, lines[0]);
finish(0, fp[0], argv[0]);
}
}