Source-Changes-HG archive

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

[src/trunk]: src/bin/cat only allocate if it would not fit in our buffer.



details:   https://anonhg.NetBSD.org/src/rev/4e6e569b0410
branches:  trunk
changeset: 782766:4e6e569b0410
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Nov 19 19:41:31 2012 +0000

description:
only allocate if it would not fit in our buffer.

diffstat:

 bin/cat/cat.c |  11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)

diffs (34 lines):

diff -r 02c33e5ca78a -r 4e6e569b0410 bin/cat/cat.c
--- a/bin/cat/cat.c     Mon Nov 19 19:34:03 2012 +0000
+++ b/bin/cat/cat.c     Mon Nov 19 19:41:31 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cat.c,v 1.51 2012/11/19 19:34:03 christos Exp $    */
+/* $NetBSD: cat.c,v 1.52 2012/11/19 19:41:31 christos Exp $    */
 
 /*
  * Copyright (c) 1989, 1993
@@ -44,7 +44,7 @@
 #if 0
 static char sccsid[] = "@(#)cat.c      8.2 (Berkeley) 4/27/95";
 #else
-__RCSID("$NetBSD: cat.c,v 1.51 2012/11/19 19:34:03 christos Exp $");
+__RCSID("$NetBSD: cat.c,v 1.52 2012/11/19 19:41:31 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -302,11 +302,12 @@
                            (size_t)sbuf.st_blksize > sizeof(fb_buf))
                                bsize = sbuf.st_blksize;
                }
-               if (bsize != 0)
+               if (bsize > sizeof(fb_buf)) {
                        buf = malloc(bsize);
+                       if (buf == NULL)
+                               warnx("malloc, using %zu buffer", bsize);
+               }
                if (buf == NULL) {
-                       if (bsize != 0)
-                               warnx("malloc, using %zu buffer", bsize);
                        bsize = sizeof(fb_buf);
                        buf = fb_buf;
                }



Home | Main Index | Thread Index | Old Index