Fix a genuine off-by-one error that caused join to dump core when

trying to use field numbers tha weren't present in the input data.
This commit is contained in:
joerg 1997-01-17 18:55:05 +00:00
parent f8d32ef174
commit ac40a92507

View File

@ -352,9 +352,9 @@ cmp(lp1, fieldno1, lp2, fieldno2)
LINE *lp1, *lp2;
u_long fieldno1, fieldno2;
{
if (lp1->fieldcnt < fieldno1)
if (lp1->fieldcnt <= fieldno1)
return (lp2->fieldcnt < fieldno2 ? 0 : 1);
if (lp2->fieldcnt < fieldno2)
if (lp2->fieldcnt <= fieldno2)
return (-1);
return (strcmp(lp1->fields[fieldno1], lp2->fields[fieldno2]));
}
@ -450,7 +450,7 @@ outfield(lp, fieldno, out_empty)
if (needsep++)
(void)printf("%c", *tabchar);
if (!ferror(stdout))
if (lp->fieldcnt < fieldno || out_empty) {
if (lp->fieldcnt <= fieldno || out_empty) {
if (empty != NULL)
(void)printf("%s", empty);
} else {