diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2007-03-13 17:33:59 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2007-03-13 17:33:59 +0000 |
commit | a8a50b52c2eff6d334e632fdbac25b5e1c391b17 (patch) | |
tree | fd36d35f5c3558f96238ec6baa9f051b4fcb2bb3 /usr.bin/sort/fsort.c | |
parent | 4c97fe67039335fd20cb5a6a7778878e3ff75f62 (diff) |
Use separate buffers in fsort.c and msort.c. Fixes a problem with
buffer corruptions for some very large files. Also fixes some
TRECHEADER vs. RECHEADER mismatches. Back in after unlock.
Diffstat (limited to 'usr.bin/sort/fsort.c')
-rw-r--r-- | usr.bin/sort/fsort.c | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/usr.bin/sort/fsort.c b/usr.bin/sort/fsort.c index cd25ab559a4..d706dd44ab5 100644 --- a/usr.bin/sort/fsort.c +++ b/usr.bin/sort/fsort.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fsort.c,v 1.17 2007/03/11 00:38:01 deraadt Exp $ */ +/* $OpenBSD: fsort.c,v 1.18 2007/03/13 17:33:58 millert Exp $ */ /*- * Copyright (c) 1993 @@ -36,7 +36,7 @@ #if 0 static char sccsid[] = "@(#)fsort.c 8.1 (Berkeley) 6/6/93"; #else -static char rcsid[] = "$OpenBSD: fsort.c,v 1.17 2007/03/11 00:38:01 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: fsort.c,v 1.18 2007/03/13 17:33:58 millert Exp $"; #endif #endif /* not lint */ @@ -53,10 +53,9 @@ static char rcsid[] = "$OpenBSD: fsort.c,v 1.17 2007/03/11 00:38:01 deraadt Exp #include <stdlib.h> #include <string.h> -u_char *buffer = NULL, *bufend = NULL, *linebuf = NULL; -size_t bufsize = BUFSIZE, linebuf_size = MAXLLEN; +u_char *linebuf; +size_t linebuf_size = MAXLLEN; struct tempfile fstack[MAXFCT]; -extern char toutpath[]; #define FSORTMAX 4 int PANIC = FSORTMAX; @@ -64,8 +63,9 @@ void fsort(int binno, int depth, union f_handle infiles, int nfiles, FILE *outfp, struct field *ftbl) { - u_char *weights, **keypos, *tmpbuf; - static u_char **keylist; + u_char *weights, **keypos, *bufend, *tmpbuf; + static u_char *buffer, **keylist; + static size_t bufsize; int ntfiles, mfct = 0, total, i, maxb, lastb, panic = 0; int c, nelem; long sizes[NBINS+1]; @@ -85,10 +85,13 @@ fsort(int binno, int depth, union f_handle infiles, int nfiles, FILE *outfp, tfield[0].weights = ascii; tfield[0].icol.num = 1; weights = ftbl[0].weights; - if (keylist == NULL) { - if ((keylist = calloc(MAXNUM, sizeof(u_char *))) == NULL) + if (buffer == NULL) { + bufsize = BUFSIZE; + if ((buffer = malloc(bufsize)) == NULL || + (keylist = calloc(MAXNUM, sizeof(u_char *))) == NULL) err(2, NULL); } + bufend = buffer + bufsize - 1; if (binno >= 0) { tfiles.top = infiles.top + nfiles; get = getnext; |