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 GCC warning about small buffer for...



details:   https://anonhg.NetBSD.org/src/rev/352291322999
branches:  trunk
changeset: 945019:352291322999
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Oct 18 19:11:35 2020 +0000

description:
make(1): fix GCC warning about small buffer for cohort_num

Since unmade_cohorts is a signed number (the code contains an underflow
check), the result of the '%' operator could be negative and result in
"#-999999", which would overflow the buffer, truncating the last digit.

diffstat:

 usr.bin/make/Makefile |  5 +----
 usr.bin/make/parse.c  |  6 +++---
 2 files changed, 4 insertions(+), 7 deletions(-)

diffs (60 lines):

diff -r 37839da9238d -r 352291322999 usr.bin/make/Makefile
--- a/usr.bin/make/Makefile     Sun Oct 18 18:31:31 2020 +0000
+++ b/usr.bin/make/Makefile     Sun Oct 18 19:11:35 2020 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.103 2020/10/05 22:15:45 rillig Exp $
+#      $NetBSD: Makefile,v 1.104 2020/10/18 19:11:35 rillig Exp $
 #      @(#)Makefile    5.2 (Berkeley) 12/28/90
 
 PROG=  make
@@ -65,7 +65,6 @@
 COPTS.dir.c+=  -Wno-error=format-truncation
 COPTS.main.c+= -Wno-error=format-truncation
 COPTS.meta.c+= -Wno-error=format-truncation
-COPTS.parse.c+=        -Wno-error=format-truncation
 .endif
 
 # Whether to compile with GCC 9 from pkgsrc, during development.
@@ -88,7 +87,6 @@
 COPTS.dir.c+=  -Wno-error=format-truncation
 COPTS.main.c+= -Wno-error=format-truncation
 COPTS.meta.c+= -Wno-error=format-truncation
-COPTS.parse.c+=        -Wno-error=format-truncation
 .endif
 
 USE_META?=     yes
@@ -160,7 +158,6 @@
 COPTS.dir.c+=  ${GCC_NO_FORMAT_TRUNCATION}
 COPTS.main.c+= ${GCC_NO_FORMAT_TRUNCATION} ${GCC_NO_STRINGOP_TRUNCATION}
 COPTS.meta.c+= ${GCC_NO_FORMAT_TRUNCATION}
-COPTS.parse.c+=        ${GCC_NO_FORMAT_TRUNCATION}
 
 COPTS+=                -Wdeclaration-after-statement
 
diff -r 37839da9238d -r 352291322999 usr.bin/make/parse.c
--- a/usr.bin/make/parse.c      Sun Oct 18 18:31:31 2020 +0000
+++ b/usr.bin/make/parse.c      Sun Oct 18 19:11:35 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: parse.c,v 1.386 2020/10/18 17:19:54 rillig Exp $       */
+/*     $NetBSD: parse.c,v 1.387 2020/10/18 19:11:35 rillig Exp $       */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -131,7 +131,7 @@
 #include "pathnames.h"
 
 /*     "@(#)parse.c    8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: parse.c,v 1.386 2020/10/18 17:19:54 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.387 2020/10/18 19:11:35 rillig Exp $");
 
 /* types and constants */
 
@@ -834,7 +834,7 @@
        cohort->centurion = gn;
        gn->unmade_cohorts++;
        snprintf(cohort->cohort_num, sizeof cohort->cohort_num, "#%d",
-                gn->unmade_cohorts % 1000000);
+                (unsigned int)gn->unmade_cohorts % 1000000);
     } else {
        /*
         * We don't want to nuke any previous flags (whatever they were) so we



Home | Main Index | Thread Index | Old Index