diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 1997-01-22 06:43:54 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 1997-01-22 06:43:54 +0000 |
commit | 897b0345ef2583e68e7b355c29d59dd1aa0da209 (patch) | |
tree | c5df313461da1a2743085e3e30fab3c1508a5d28 /usr.bin | |
parent | aa47e726ca694936eb0f7133827762410798817e (diff) |
Fix off-by-one differently--add an extra byte to buffer (ick).
Don't dump core on empty file.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/sort/files.c | 6 | ||||
-rw-r--r-- | usr.bin/sort/fsort.c | 8 | ||||
-rw-r--r-- | usr.bin/sort/msort.c | 37 |
3 files changed, 27 insertions, 24 deletions
diff --git a/usr.bin/sort/files.c b/usr.bin/sort/files.c index f345877e48e..a11a882ccae 100644 --- a/usr.bin/sort/files.c +++ b/usr.bin/sort/files.c @@ -1,4 +1,4 @@ -/* $OpenBSD: files.c,v 1.1 1997/01/20 19:39:50 millert Exp $ */ +/* $OpenBSD: files.c,v 1.2 1997/01/22 06:43:51 millert Exp $ */ /*- * Copyright (c) 1993 @@ -40,7 +40,7 @@ #if 0 static char sccsid[] = "@(#)files.c 8.1 (Berkeley) 6/6/93"; #else -static char rcsid[] = "$OpenBSD: files.c,v 1.1 1997/01/20 19:39:50 millert Exp $"; +static char rcsid[] = "$OpenBSD: files.c,v 1.2 1997/01/22 06:43:51 millert Exp $"; #endif #endif /* not lint */ @@ -184,7 +184,7 @@ makeline(flno, filelist, nfiles, buffer, bufend, dummy2) if(flno >= 0) fstack[flno].fp = 0; } else { buffer->data[100] = '\000'; - warnx("line too long:ignoring %s...", buffer->data); + warnx("line too long: ignoring %s...", buffer->data); } } } diff --git a/usr.bin/sort/fsort.c b/usr.bin/sort/fsort.c index 122608ae646..3537dfb9f5e 100644 --- a/usr.bin/sort/fsort.c +++ b/usr.bin/sort/fsort.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fsort.c,v 1.2 1997/01/22 05:49:19 millert Exp $ */ +/* $OpenBSD: fsort.c,v 1.3 1997/01/22 06:43:52 millert Exp $ */ /*- * Copyright (c) 1993 @@ -40,7 +40,7 @@ #if 0 static char sccsid[] = "@(#)fsort.c 8.1 (Berkeley) 6/6/93"; #else -static char rcsid[] = "$OpenBSD: fsort.c,v 1.2 1997/01/22 05:49:19 millert Exp $"; +static char rcsid[] = "$OpenBSD: fsort.c,v 1.3 1997/01/22 06:43:52 millert Exp $"; #endif #endif /* not lint */ @@ -92,12 +92,12 @@ fsort(binno, depth, infiles, nfiles, outfp, ftbl) tfield[0].icol.num = 1; weights = ftbl[0].weights; if (!buffer) { - buffer = malloc(BUFSIZE); + buffer = malloc(BUFSIZE + 1); keylist = malloc(MAXNUM * sizeof(u_char *)); if (!SINGL_FLD) linebuf = malloc(MAXLLEN); } - bufend = buffer + BUFSIZE - 1; + bufend = buffer + BUFSIZE; if (binno >= 0) { tfiles.top = infiles.top + nfiles; get = getnext; diff --git a/usr.bin/sort/msort.c b/usr.bin/sort/msort.c index 09081480e67..5e2fc6556d6 100644 --- a/usr.bin/sort/msort.c +++ b/usr.bin/sort/msort.c @@ -1,4 +1,4 @@ -/* $OpenBSD: msort.c,v 1.1 1997/01/20 19:39:53 millert Exp $ */ +/* $OpenBSD: msort.c,v 1.2 1997/01/22 06:43:53 millert Exp $ */ /*- * Copyright (c) 1993 @@ -40,7 +40,7 @@ #if 0 static char sccsid[] = "@(#)msort.c 8.1 (Berkeley) 6/6/93"; #else -static char rcsid[] = "$OpenBSD: msort.c,v 1.1 1997/01/20 19:39:53 millert Exp $"; +static char rcsid[] = "$OpenBSD: msort.c,v 1.2 1997/01/22 06:43:53 millert Exp $"; #endif #endif /* not lint */ @@ -151,6 +151,7 @@ merge(infl0, nfiles, get, outfp, put, ftbl) int c, i, j; union f_handle dummy = {0}; struct mfile *flist[16], *cfile; + for (i = j = 0; i < nfiles; i++) { cfile = (MFILE *) (buffer + i * LALIGN(MAXLLEN + sizeof(TMFILE))); @@ -170,22 +171,24 @@ merge(infl0, nfiles, get, outfp, put, ftbl) } j++; } - cfile = cfilebuf; - cfile->flno = flist[0]->flno; - cfile->end = cfile->rec->data + MAXLLEN; - while (nfiles) { - for (c = 1; c == 1;) { - if (EOF == (c = get(cfile->flno, dummy, nfiles, - cfile->rec, cfile->end, ftbl))) { - put(flist[0]->rec, outfp); - memmove(flist, flist + 1, - sizeof(MFILE *) * (--nfiles)); - cfile->flno = flist[0]->flno; - break; + if (nfiles > 0) { + cfile = cfilebuf; + cfile->flno = flist[0]->flno; + cfile->end = cfile->rec->data + MAXLLEN; + while (nfiles) { + for (c = 1; c == 1;) { + if (EOF == (c = get(cfile->flno, dummy, nfiles, + cfile->rec, cfile->end, ftbl))) { + put(flist[0]->rec, outfp); + memmove(flist, flist + 1, + sizeof(MFILE *) * (--nfiles)); + cfile->flno = flist[0]->flno; + break; + } + if (!(c = insert(flist, &cfile, nfiles, DELETE))) + put(cfile->rec, outfp); } - if (!(c = insert(flist, &cfile, nfiles, DELETE))) - put(cfile->rec, outfp); - } + } } } |