Module Name:    src
Committed By:   rillig
Date:           Sun Jan  3 18:48:37 UTC 2021

Modified Files:
        src/usr.bin/xlint/lint1: Makefile decl.c err.c lint1.h
Added Files:
        src/usr.bin/xlint/lint1: Makefile.err-msgs-h

Log Message:
lint: in DEBUG mode, verify printf parameters for messages

Since several years GCC validates printf-style strings, and there is no
reason not to let GCC do that work.  This prevents bugs like the
segmentation fault that was fixed in tree.c 1.109 from 2021-01-01.

By default, lint is compiled with DEBUG off, but it's easy enough to
compile it in debug mode once in a while.


To generate a diff of this commit:
cvs rdiff -u -r1.54 -r1.55 src/usr.bin/xlint/lint1/Makefile
cvs rdiff -u -r0 -r1.1 src/usr.bin/xlint/lint1/Makefile.err-msgs-h
cvs rdiff -u -r1.106 -r1.107 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.63 -r1.64 src/usr.bin/xlint/lint1/err.c
cvs rdiff -u -r1.48 -r1.49 src/usr.bin/xlint/lint1/lint1.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/xlint/lint1/Makefile
diff -u src/usr.bin/xlint/lint1/Makefile:1.54 src/usr.bin/xlint/lint1/Makefile:1.55
--- src/usr.bin/xlint/lint1/Makefile:1.54	Fri Jan  1 14:51:44 2021
+++ src/usr.bin/xlint/lint1/Makefile	Sun Jan  3 18:48:37 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.54 2021/01/01 14:51:44 rillig Exp $
+#	$NetBSD: Makefile,v 1.55 2021/01/03 18:48:37 rillig Exp $
 
 .include <bsd.own.mk>
 
@@ -38,9 +38,11 @@ LDADD+=		-ll
 DPADD+=		${LIBL}
 .endif
 
+.include "Makefile.err-msgs-h"
 .include "Makefile.ops-h"
 .include "Makefile.ops-c"
 
 .include <bsd.prog.mk>
 
 ${SRCS}: ops.h
+${SRCS:Nerr.c}: err-msgs.h

Index: src/usr.bin/xlint/lint1/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.106 src/usr.bin/xlint/lint1/decl.c:1.107
--- src/usr.bin/xlint/lint1/decl.c:1.106	Sun Jan  3 17:42:45 2021
+++ src/usr.bin/xlint/lint1/decl.c	Sun Jan  3 18:48:37 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.106 2021/01/03 17:42:45 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.107 2021/01/03 18:48:37 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: decl.c,v 1.106 2021/01/03 17:42:45 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.107 2021/01/03 18:48:37 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -3206,7 +3206,7 @@ print_previous_declaration(int msg, sym_
 	cpos = curr_pos;
 	curr_pos = psym->s_def_pos;
 	if (msg != -1) {
-		message(msg);
+		(message)(msg);
 	} else if (psym->s_def == DEF || psym->s_def == TDEF) {
 		/* previous definition of %s */
 		message(261, psym->s_name);

Index: src/usr.bin/xlint/lint1/err.c
diff -u src/usr.bin/xlint/lint1/err.c:1.63 src/usr.bin/xlint/lint1/err.c:1.64
--- src/usr.bin/xlint/lint1/err.c:1.63	Sun Jan  3 17:42:45 2021
+++ src/usr.bin/xlint/lint1/err.c	Sun Jan  3 18:48:37 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: err.c,v 1.63 2021/01/03 17:42:45 rillig Exp $	*/
+/*	$NetBSD: err.c,v 1.64 2021/01/03 18:48:37 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: err.c,v 1.63 2021/01/03 17:42:45 rillig Exp $");
+__RCSID("$NetBSD: err.c,v 1.64 2021/01/03 18:48:37 rillig Exp $");
 #endif
 
 #include <sys/types.h>
@@ -464,7 +464,7 @@ vwarning(int n, va_list ap)
 }
 
 void
-error(int n, ...)
+(error)(int n, ...)
 {
 	va_list	ap;
 
@@ -502,7 +502,7 @@ assert_failed(const char *file, int line
 }
 
 void
-warning(int n, ...)
+(warning)(int n, ...)
 {
 	va_list	ap;
 
@@ -512,7 +512,7 @@ warning(int n, ...)
 }
 
 void
-message(int n, ...)
+(message)(int n, ...)
 {
 	va_list	ap;
 	const	char *fn;
@@ -535,7 +535,7 @@ message(int n, ...)
  * "right"... [perry, 2 Nov 2002]
 */
 void
-c99ism(int n, ...)
+(c99ism)(int n, ...)
 {
 	va_list	ap;
 	bool extensions_ok = Sflag || gflag;
@@ -550,7 +550,7 @@ c99ism(int n, ...)
 }
 
 void
-gnuism(int n, ...)
+(gnuism)(int n, ...)
 {
 	va_list	ap;
 

Index: src/usr.bin/xlint/lint1/lint1.h
diff -u src/usr.bin/xlint/lint1/lint1.h:1.48 src/usr.bin/xlint/lint1/lint1.h:1.49
--- src/usr.bin/xlint/lint1/lint1.h:1.48	Sat Jan  2 18:26:44 2021
+++ src/usr.bin/xlint/lint1/lint1.h	Sun Jan  3 18:48:37 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.48 2021/01/02 18:26:44 rillig Exp $ */
+/* $NetBSD: lint1.h,v 1.49 2021/01/03 18:48:37 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -33,6 +33,7 @@
  */
 
 #include "lint.h"
+#include "err-msgs.h"
 #include "op.h"
 
 /*
@@ -435,3 +436,26 @@ typedef	struct err_set {
 #endif
 
 extern err_set	msgset;
+
+
+#ifdef DEBUG
+#  include "err-msgs.h"
+
+/* ARGSUSED */
+static inline void __attribute__((format(printf, 1, 2)))
+check_printf(const char *fmt, ...)
+{
+}
+
+#  define wrap_check_printf(func, id, args...)				\
+	do {								\
+		check_printf(__CONCAT(MSG_, id), ##args);		\
+		(func)(id, ##args);					\
+	} while (/*CONSTCOND*/0)
+
+#  define error(id, args...) wrap_check_printf(error, id, ##args)
+#  define warning(id, args...) wrap_check_printf(warning, id, ##args)
+#  define message(id, args...) wrap_check_printf(message, id, ##args)
+#  define gnuism(id, args...) wrap_check_printf(gnuism, id, ##args)
+#  define c99ism(id, args...) wrap_check_printf(c99ism, id, ##args)
+#endif

Added files:

Index: src/usr.bin/xlint/lint1/Makefile.err-msgs-h
diff -u /dev/null src/usr.bin/xlint/lint1/Makefile.err-msgs-h:1.1
--- /dev/null	Sun Jan  3 18:48:37 2021
+++ src/usr.bin/xlint/lint1/Makefile.err-msgs-h	Sun Jan  3 18:48:37 2021
@@ -0,0 +1,13 @@
+#	$NetBSD: Makefile.err-msgs-h,v 1.1 2021/01/03 18:48:37 rillig Exp $
+
+err-msgs.h: err.c Makefile.err-msgs-h
+	${_MKTARGET_CREATE}
+	sp='[[:space:]]*'; \
+	from="^$$sp\(\".*\"\)\,$$sp/\*$$sp\([0-9][0-9]*\)$$sp\*/\$$"; \
+	${TOOL_SED} -n -e "s,$$from,#define MSG_\2 \1,p" < err.c > ${.TARGET}.tmp
+	mv -f ${.TARGET}.tmp ${.TARGET}
+
+CLEANFILES+=	err-msgs.h
+DPSRCS+=	err-msgs.h
+
+externs1.h: err-msgs.h

Reply via email to