diff options
| author | dsl <dsl@NetBSD.org> | 2009-09-28 20:30:01 +0000 |
|---|---|---|
| committer | dsl <dsl@NetBSD.org> | 2009-09-28 20:30:01 +0000 |
| commit | eab2f96cf50fd63fdd9f42a63f21f46dd4ec6dc6 (patch) | |
| tree | 93a8d4cb7ed78f18abc3d2bcf464af2f12be5935 /usr.bin/sort | |
| parent | 8e181d0741dbde8c0290f0032e412263ea182832 (diff) | |
Fix borked fix for sort relying on realloc() changing the buffer end.
Sorts of more than 8MB data now probably work again.
Diffstat (limited to 'usr.bin/sort')
| -rw-r--r-- | usr.bin/sort/files.c | 32 | ||||
| -rw-r--r-- | usr.bin/sort/fsort.c | 5 | ||||
| -rw-r--r-- | usr.bin/sort/sort.h | 3 |
3 files changed, 24 insertions, 16 deletions
diff --git a/usr.bin/sort/files.c b/usr.bin/sort/files.c index 4b937ec626e..07f429162e5 100644 --- a/usr.bin/sort/files.c +++ b/usr.bin/sort/files.c @@ -1,4 +1,4 @@ -/* $NetBSD: files.c,v 1.38 2009/09/26 21:16:55 dsl Exp $ */ +/* $NetBSD: files.c,v 1.39 2009/09/28 20:30:01 dsl Exp $ */ /*- * Copyright (c) 2000-2003 The NetBSD Foundation, Inc. @@ -65,7 +65,7 @@ #include "fsort.h" #ifndef lint -__RCSID("$NetBSD: files.c,v 1.38 2009/09/26 21:16:55 dsl Exp $"); +__RCSID("$NetBSD: files.c,v 1.39 2009/09/28 20:30:01 dsl Exp $"); __SCCSID("@(#)files.c 8.1 (Berkeley) 6/6/93"); #endif /* not lint */ @@ -77,30 +77,36 @@ static ssize_t seq(FILE *, u_char **); * this is called when there is no special key. It's only called * in the first fsort pass. */ + +static u_char *opos; +static size_t osz; + +void +makeline_copydown(RECHEADER *recbuf) +{ + memmove(recbuf->data, opos, osz); +} + int makeline(FILE *fp, RECHEADER *recbuf, u_char *bufend, struct field *dummy2) { - static u_char *opos = NULL; - static size_t osz; u_char *pos; int c; pos = recbuf->data; - if (opos != NULL) { + if (osz != 0) { /* * Buffer shortage is solved by either of two ways: * o flush previous buffered data and start using the - * buffer from start (see fsort()) - * o realloc buffer and bump bufend + * buffer from start. + * makeline_copydown() above must be called. + * o realloc buffer * - * The former is preferred, realloc is only done when - * there is exactly one item in buffer which does not fit. + * This code has relied on realloc changing 'bufend', + * but that isn't necessarily true. */ - if (pos != opos) - memmove(pos, opos, osz); - pos += osz; - opos = NULL; + osz = 0; } while (pos < bufend) { diff --git a/usr.bin/sort/fsort.c b/usr.bin/sort/fsort.c index 72e6169d6c8..ba73c87965d 100644 --- a/usr.bin/sort/fsort.c +++ b/usr.bin/sort/fsort.c @@ -1,4 +1,4 @@ -/* $NetBSD: fsort.c,v 1.42 2009/09/26 21:16:55 dsl Exp $ */ +/* $NetBSD: fsort.c,v 1.43 2009/09/28 20:30:01 dsl Exp $ */ /*- * Copyright (c) 2000-2003 The NetBSD Foundation, Inc. @@ -72,7 +72,7 @@ #include "fsort.h" #ifndef lint -__RCSID("$NetBSD: fsort.c,v 1.42 2009/09/26 21:16:55 dsl Exp $"); +__RCSID("$NetBSD: fsort.c,v 1.43 2009/09/28 20:30:01 dsl Exp $"); __SCCSID("@(#)fsort.c 8.1 (Berkeley) 6/6/93"); #endif /* not lint */ @@ -123,6 +123,7 @@ fsort(struct filelist *filelist, int nfiles, FILE *outfp, struct field *ftbl) keypos = keylist; nelem = 0; crec = buffer; + makeline_copydown(crec); /* Loop reading records */ for (;;) { diff --git a/usr.bin/sort/sort.h b/usr.bin/sort/sort.h index 8a7de4c0797..4593ffd2251 100644 --- a/usr.bin/sort/sort.h +++ b/usr.bin/sort/sort.h @@ -1,4 +1,4 @@ -/* $NetBSD: sort.h,v 1.29 2009/09/26 21:16:55 dsl Exp $ */ +/* $NetBSD: sort.h,v 1.30 2009/09/28 20:30:01 dsl Exp $ */ /*- * Copyright (c) 2000-2003 The NetBSD Foundation, Inc. @@ -187,6 +187,7 @@ void fsort(struct filelist *, int, FILE *, struct field *); int geteasy(FILE *, RECHEADER *, u_char *, struct field *); int makekey(FILE *, RECHEADER *, u_char *, struct field *); int makeline(FILE *, RECHEADER *, u_char *, struct field *); +void makeline_copydown(RECHEADER *); int optval(int, int); void order(struct filelist *, struct field *); void putline(const RECHEADER *, FILE *); |
