Module Name: src Committed By: nia Date: Tue Nov 2 08:04:20 UTC 2021
Modified Files: src/bin/ed: undo.c Log Message: ed(1): use reallocarr instead of realloc(x * y) To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/bin/ed/undo.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/bin/ed/undo.c diff -u src/bin/ed/undo.c:1.7 src/bin/ed/undo.c:1.8 --- src/bin/ed/undo.c:1.7 Fri Jan 4 19:13:58 2019 +++ src/bin/ed/undo.c Tue Nov 2 08:04:20 2021 @@ -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 @@ long u_p = 0; /* undo stack pointer 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);