Module Name: src
Committed By: dsl
Date: Mon Sep 28 20:30:01 UTC 2009
Modified Files:
src/usr.bin/sort: files.c fsort.c sort.h
Log Message:
Fix borked fix for sort relying on realloc() changing the buffer end.
Sorts of more than 8MB data now probably work again.
To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/usr.bin/sort/files.c
cvs rdiff -u -r1.42 -r1.43 src/usr.bin/sort/fsort.c
cvs rdiff -u -r1.29 -r1.30 src/usr.bin/sort/sort.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/sort/files.c
diff -u src/usr.bin/sort/files.c:1.38 src/usr.bin/sort/files.c:1.39
--- src/usr.bin/sort/files.c:1.38 Sat Sep 26 21:16:55 2009
+++ src/usr.bin/sort/files.c Mon Sep 28 20:30:01 2009
@@ -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 @@
* 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) {
Index: src/usr.bin/sort/fsort.c
diff -u src/usr.bin/sort/fsort.c:1.42 src/usr.bin/sort/fsort.c:1.43
--- src/usr.bin/sort/fsort.c:1.42 Sat Sep 26 21:16:55 2009
+++ src/usr.bin/sort/fsort.c Mon Sep 28 20:30:01 2009
@@ -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 @@
keypos = keylist;
nelem = 0;
crec = buffer;
+ makeline_copydown(crec);
/* Loop reading records */
for (;;) {
Index: src/usr.bin/sort/sort.h
diff -u src/usr.bin/sort/sort.h:1.29 src/usr.bin/sort/sort.h:1.30
--- src/usr.bin/sort/sort.h:1.29 Sat Sep 26 21:16:55 2009
+++ src/usr.bin/sort/sort.h Mon Sep 28 20:30:01 2009
@@ -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 @@
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 *);