Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/make make(1): fix variable length array in Buf_AddInt



details:   https://anonhg.NetBSD.org/src/rev/192c4f76fd5f
branches:  trunk
changeset: 1012780:192c4f76fd5f
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Aug 09 18:52:03 2020 +0000

description:
make(1): fix variable length array in Buf_AddInt

GCC 5 complained about this, but only when make is build with both
USE_COVERAGE=yes and USE_FORT=yes.

diffstat:

 usr.bin/make/buf.c |  13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)

diffs (40 lines):

diff -r 6f3d1bc007d4 -r 192c4f76fd5f usr.bin/make/buf.c
--- a/usr.bin/make/buf.c        Sun Aug 09 17:18:47 2020 +0000
+++ b/usr.bin/make/buf.c        Sun Aug 09 18:52:03 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: buf.c,v 1.32 2020/08/08 18:54:04 rillig Exp $  */
+/*     $NetBSD: buf.c,v 1.33 2020/08/09 18:52:03 rillig Exp $  */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -70,14 +70,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: buf.c,v 1.32 2020/08/08 18:54:04 rillig Exp $";
+static char rcsid[] = "$NetBSD: buf.c,v 1.33 2020/08/09 18:52:03 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)buf.c      8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: buf.c,v 1.32 2020/08/08 18:54:04 rillig Exp $");
+__RCSID("$NetBSD: buf.c,v 1.33 2020/08/09 18:52:03 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -143,8 +143,11 @@
      * We calculate the space needed for the octal representation, and
      * add enough slop to cope with a '-' sign and a trailing '\0'.
      */
-    size_t bits = sizeof(int) * CHAR_BIT;
-    char buf[1 + (bits + 2) / 3 + 1];
+    enum {
+        bits  = sizeof(int) * CHAR_BIT,
+        buf_size = 1 + (bits + 2) / 3 + 1
+    };
+    char buf[buf_size];
 
     size_t len = (size_t)snprintf(buf, sizeof buf, "%d", n);
     Buf_AddBytes(bp, buf, len);



Home | Main Index | Thread Index | Old Index