Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/sort Fix borked fix for sort relying on realloc() ch...



details:   https://anonhg.NetBSD.org/src/rev/282897353fe0
branches:  trunk
changeset: 747719:282897353fe0
user:      dsl <dsl%NetBSD.org@localhost>
date:      Mon Sep 28 20:30:01 2009 +0000

description:
Fix borked fix for sort relying on realloc() changing the buffer end.
Sorts of more than 8MB data now probably work again.

diffstat:

 usr.bin/sort/files.c |  32 +++++++++++++++++++-------------
 usr.bin/sort/fsort.c |   5 +++--
 usr.bin/sort/sort.h  |   3 ++-
 3 files changed, 24 insertions(+), 16 deletions(-)

diffs (109 lines):

diff -r be668f91958d -r 282897353fe0 usr.bin/sort/files.c
--- a/usr.bin/sort/files.c      Mon Sep 28 18:28:59 2009 +0000
+++ b/usr.bin/sort/files.c      Mon Sep 28 20:30:01 2009 +0000
@@ -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) {
diff -r be668f91958d -r 282897353fe0 usr.bin/sort/fsort.c
--- a/usr.bin/sort/fsort.c      Mon Sep 28 18:28:59 2009 +0000
+++ b/usr.bin/sort/fsort.c      Mon Sep 28 20:30:01 2009 +0000
@@ -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 (;;) {
diff -r be668f91958d -r 282897353fe0 usr.bin/sort/sort.h
--- a/usr.bin/sort/sort.h       Mon Sep 28 18:28:59 2009 +0000
+++ b/usr.bin/sort/sort.h       Mon Sep 28 20:30:01 2009 +0000
@@ -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 *);



Home | Main Index | Thread Index | Old Index