Source-Changes-HG archive

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

[src/trunk]: src/bin/rcp realloc pedant



details:   https://anonhg.NetBSD.org/src/rev/5eebeb2d61ea
branches:  trunk
changeset: 552121:5eebeb2d61ea
user:      itojun <itojun%NetBSD.org@localhost>
date:      Fri Sep 19 08:46:32 2003 +0000

description:
realloc pedant

diffstat:

 bin/rcp/util.c |  10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)

diffs (42 lines):

diff -r 4ce4ca891f4e -r 5eebeb2d61ea bin/rcp/util.c
--- a/bin/rcp/util.c    Fri Sep 19 08:43:12 2003 +0000
+++ b/bin/rcp/util.c    Fri Sep 19 08:46:32 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: util.c,v 1.6 2003/08/07 09:05:27 agc Exp $     */
+/*     $NetBSD: util.c,v 1.7 2003/09/19 08:46:32 itojun Exp $  */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)util.c     8.2 (Berkeley) 4/2/94";
 #else
-__RCSID("$NetBSD: util.c,v 1.6 2003/08/07 09:05:27 agc Exp $");
+__RCSID("$NetBSD: util.c,v 1.7 2003/09/19 08:46:32 itojun Exp $");
 #endif
 #endif /* not lint */
 
@@ -141,6 +141,7 @@
 {
        struct stat stb;
        size_t size;
+       char *nbuf;
 
        if (fstat(fd, &stb) < 0) {
                run_err("fstat: %s", strerror(errno));
@@ -151,11 +152,14 @@
                size = blksize;
        if (bp->cnt >= size)
                return (bp);
-       if ((bp->buf = realloc(bp->buf, size)) == NULL) {
+       if ((nbuf = realloc(bp->buf, size)) == NULL) {
+               free(bp->buf);
+               bp->buf = NULL;
                bp->cnt = 0;
                run_err("%s", strerror(errno));
                return (0);
        }
+       bp->buf = nbuf;
        bp->cnt = size;
        return (bp);
 }



Home | Main Index | Thread Index | Old Index