Source-Changes-HG archive

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

[src/trunk]: src/bin/csh Use the right size for several calloc calls.



details:   https://anonhg.NetBSD.org/src/rev/3a9cc2c62c56
branches:  trunk
changeset: 937093:3a9cc2c62c56
user:      dholland <dholland%NetBSD.org@localhost>
date:      Sun Aug 09 00:34:21 2020 +0000

description:
Use the right size for several calloc calls.

When allocating for a Char **, it should use sizeof(Char *), not
sizeof(Char **). This doesn't actually affect the results except
on DS9000 though :-)

diffstat:

 bin/csh/dir.c   |  6 +++---
 bin/csh/lex.c   |  9 +++++----
 bin/csh/parse.c |  7 ++++---
 3 files changed, 12 insertions(+), 10 deletions(-)

diffs (92 lines):

diff -r 62880a53d495 -r 3a9cc2c62c56 bin/csh/dir.c
--- a/bin/csh/dir.c     Sun Aug 09 00:22:53 2020 +0000
+++ b/bin/csh/dir.c     Sun Aug 09 00:34:21 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dir.c,v 1.34 2020/08/09 00:22:53 dholland Exp $ */
+/* $NetBSD: dir.c,v 1.35 2020/08/09 00:34:21 dholland Exp $ */
 
 /*-
  * Copyright (c) 1980, 1991, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)dir.c      8.1 (Berkeley) 5/31/93";
 #else
-__RCSID("$NetBSD: dir.c,v 1.34 2020/08/09 00:22:53 dholland Exp $");
+__RCSID("$NetBSD: dir.c,v 1.35 2020/08/09 00:34:21 dholland Exp $");
 #endif
 #endif /* not lint */
 
@@ -147,7 +147,7 @@
      * other junk characters glob will fail.
      */
 
-    vec = xmalloc((size_t)(2 * sizeof(Char **)));
+    vec = xmalloc(2 * sizeof(*vec));
     vec[0] = Strsave(dp);
     vec[1] = 0;
     setq(STRcwd, vec, &shvhed);
diff -r 62880a53d495 -r 3a9cc2c62c56 bin/csh/lex.c
--- a/bin/csh/lex.c     Sun Aug 09 00:22:53 2020 +0000
+++ b/bin/csh/lex.c     Sun Aug 09 00:34:21 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.35 2020/08/09 00:22:53 dholland Exp $ */
+/* $NetBSD: lex.c,v 1.36 2020/08/09 00:34:21 dholland Exp $ */
 
 /*-
  * Copyright (c) 1980, 1991, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)lex.c      8.1 (Berkeley) 5/31/93";
 #else
-__RCSID("$NetBSD: lex.c,v 1.35 2020/08/09 00:22:53 dholland Exp $");
+__RCSID("$NetBSD: lex.c,v 1.36 2020/08/09 00:34:21 dholland Exp $");
 #endif
 #endif /* not lint */
 
@@ -1453,7 +1453,8 @@
     if (buf >= fblocks) {
        Char **nfbuf;
 
-       nfbuf = xcalloc((size_t) (fblocks + 2), sizeof(char **));
+       /* XXX the cast is needed because fblocks is signed */
+       nfbuf = xcalloc((size_t)(fblocks + 2), sizeof(*nfbuf));
        if (fbuf) {
            (void)blkcpy(nfbuf, fbuf);
            free(fbuf);
@@ -1623,7 +1624,7 @@
        return;
     if (lseek(SHIN, (off_t) 0, SEEK_CUR) < 0 || errno == ESPIPE)
        return;
-    fbuf = xcalloc(2, sizeof(Char **));
+    fbuf = xcalloc(2, sizeof(*fbuf));
     fblocks = 1;
     fbuf[0] = xcalloc(BUFSIZE, sizeof(Char));
     fseekp = fbobp = feobp = lseek(SHIN, (off_t) 0, SEEK_CUR);
diff -r 62880a53d495 -r 3a9cc2c62c56 bin/csh/parse.c
--- a/bin/csh/parse.c   Sun Aug 09 00:22:53 2020 +0000
+++ b/bin/csh/parse.c   Sun Aug 09 00:34:21 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: parse.c,v 1.20 2020/08/09 00:22:53 dholland Exp $ */
+/* $NetBSD: parse.c,v 1.21 2020/08/09 00:34:21 dholland Exp $ */
 
 /*-
  * Copyright (c) 1980, 1991, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)parse.c    8.1 (Berkeley) 5/31/93";
 #else
-__RCSID("$NetBSD: parse.c,v 1.20 2020/08/09 00:22:53 dholland Exp $");
+__RCSID("$NetBSD: parse.c,v 1.21 2020/08/09 00:34:21 dholland Exp $");
 #endif
 #endif /* not lint */
 
@@ -509,7 +509,8 @@
     if (n < 0)
        n = 0;
     t = xcalloc(1, sizeof(*t));
-    av = xcalloc((size_t)(n + 1), sizeof(Char **));
+    /* XXX the cast is needed because n is signed */
+    av = xcalloc((size_t)(n + 1), sizeof(*av));
     t->t_dcom = av;
     n = 0;
     if (p2->word[0] == ')')



Home | Main Index | Thread Index | Old Index