Source-Changes-HG archive

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

[src/trunk]: src/games/worms Garbage collect "char *mp" - it used to point at...



details:   https://anonhg.NetBSD.org/src/rev/11a683556f58
branches:  trunk
changeset: 374263:11a683556f58
user:      kre <kre%NetBSD.org@localhost>
date:      Sat Apr 15 13:00:30 2023 +0000

description:
Garbage collect "char *mp" - it used to point at memory malloc()'d
to hold the termcap entry, back when worms used termcap rather than
curses, and termcap was termcap, rather that a terminfo wannabe.

This should have been removed when worms was converted to curses in
1999, but wasn't, so worms has been doing a meaningless malloc(1024)
and never using the result, ever since.

While here, since the line needed changing anyway to remove mp,
change a malloc() of a product into calloc() so it can deal with
any possible (admittedly extremely unlikely here) integer overflows.

NFCI

diffstat:

 games/worms/worms.c |  9 +++------
 1 files changed, 3 insertions(+), 6 deletions(-)

diffs (39 lines):

diff -r a5ac527fb75c -r 11a683556f58 games/worms/worms.c
--- a/games/worms/worms.c       Sat Apr 15 12:59:02 2023 +0000
+++ b/games/worms/worms.c       Sat Apr 15 13:00:30 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: worms.c,v 1.23 2020/10/14 07:32:53 nia Exp $   */
+/*     $NetBSD: worms.c,v 1.24 2023/04/15 13:00:30 kre Exp $   */
 
 /*
  * Copyright (c) 1980, 1993
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = "@(#)worms.c    8.1 (Berkeley) 5/31/93";
 #else
-__RCSID("$NetBSD: worms.c,v 1.23 2020/10/14 07:32:53 nia Exp $");
+__RCSID("$NetBSD: worms.c,v 1.24 2023/04/15 13:00:30 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -193,10 +193,8 @@ main(int argc, char *argv[])
        int CO, LI, last, bottom, ch, length, number, trail;
        short **ref;
        const char *field;
-       char *mp;
        unsigned int delay = 20000;
 
-       mp = NULL;
        length = 16;
        number = 3;
        trail = ' ';
@@ -232,8 +230,7 @@ main(int argc, char *argv[])
                        exit(1);
                }
 
-       if (!(worm = malloc((size_t)number *
-           sizeof(struct worm))) || !(mp = malloc((size_t)1024)))
+       if (!(worm = calloc((size_t)number, sizeof(struct worm))))
                nomem();
        if (!initscr())
                errx(0, "couldn't initialize screen");



Home | Main Index | Thread Index | Old Index