Source-Changes-HG archive

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

[src/trunk]: src/bin/ed ed(1): use reallocarr instead of realloc(x * y)



details:   https://anonhg.NetBSD.org/src/rev/dc22ea0e0fc6
branches:  trunk
changeset: 1024751:dc22ea0e0fc6
user:      nia <nia%NetBSD.org@localhost>
date:      Tue Nov 02 08:04:20 2021 +0000

description:
ed(1): use reallocarr instead of realloc(x * y)

diffstat:

 bin/ed/undo.c |  12 +++++-------
 1 files changed, 5 insertions(+), 7 deletions(-)

diffs (41 lines):

diff -r abf0023c1efa -r dc22ea0e0fc6 bin/ed/undo.c
--- a/bin/ed/undo.c     Tue Nov 02 06:54:10 2021 +0000
+++ b/bin/ed/undo.c     Tue Nov 02 08:04:20 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: undo.c,v 1.7 2019/01/04 19:13:58 maya Exp $    */
+/*     $NetBSD: undo.c,v 1.8 2021/11/02 08:04:20 nia Exp $     */
 
 /* undo.c: This file contains the undo routines for the ed line editor */
 /*-
@@ -32,7 +32,7 @@
 #if 0
 static char *rcsid = "@(#)undo.c,v 1.1 1994/02/01 00:34:44 alm Exp";
 #else
-__RCSID("$NetBSD: undo.c,v 1.7 2019/01/04 19:13:58 maya Exp $");
+__RCSID("$NetBSD: undo.c,v 1.8 2021/11/02 08:04:20 nia Exp $");
 #endif
 #endif /* not lint */
 
@@ -48,19 +48,17 @@
 undo_t *
 push_undo_stack(int type, long from, long to)
 {
-       undo_t *t;
+       int err;
 
-       t = ustack;
        if (u_p < usize ||
-           (t = (undo_t *) realloc(ustack, (usize += USIZE) * sizeof(undo_t))) != NULL) {
-               ustack = t;
+           (err = reallocarr(&ustack, usize += USIZE, sizeof(undo_t))) == 0) {
                ustack[u_p].type = type;
                ustack[u_p].t = get_addressed_line_node(to);
                ustack[u_p].h = get_addressed_line_node(from);
                return ustack + u_p++;
        }
        /* out of memory - release undo stack */
-       fprintf(stderr, "%s\n", strerror(errno));
+       fprintf(stderr, "%s\n", strerror(err));
        seterrmsg("out of memory");
        clear_undo_stack();
        free(ustack);



Home | Main Index | Thread Index | Old Index