Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/xlint/lint1 lint: in DEBUG mode, verify printf param...
details: https://anonhg.NetBSD.org/src/rev/0fe98acca1b2
branches: trunk
changeset: 958401:0fe98acca1b2
user: rillig <rillig%NetBSD.org@localhost>
date: Sun Jan 03 18:48:37 2021 +0000
description:
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.
diffstat:
usr.bin/xlint/lint1/Makefile | 4 +++-
usr.bin/xlint/lint1/Makefile.err-msgs-h | 13 +++++++++++++
usr.bin/xlint/lint1/decl.c | 6 +++---
usr.bin/xlint/lint1/err.c | 14 +++++++-------
usr.bin/xlint/lint1/lint1.h | 26 +++++++++++++++++++++++++-
5 files changed, 51 insertions(+), 12 deletions(-)
diffs (172 lines):
diff -r 68233a4a8777 -r 0fe98acca1b2 usr.bin/xlint/lint1/Makefile
--- a/usr.bin/xlint/lint1/Makefile Sun Jan 03 18:35:51 2021 +0000
+++ b/usr.bin/xlint/lint1/Makefile Sun Jan 03 18:48:37 2021 +0000
@@ -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 @@
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
diff -r 68233a4a8777 -r 0fe98acca1b2 usr.bin/xlint/lint1/Makefile.err-msgs-h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/xlint/lint1/Makefile.err-msgs-h Sun Jan 03 18:48:37 2021 +0000
@@ -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
diff -r 68233a4a8777 -r 0fe98acca1b2 usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c Sun Jan 03 18:35:51 2021 +0000
+++ b/usr.bin/xlint/lint1/decl.c Sun Jan 03 18:48:37 2021 +0000
@@ -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 @@
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);
diff -r 68233a4a8777 -r 0fe98acca1b2 usr.bin/xlint/lint1/err.c
--- a/usr.bin/xlint/lint1/err.c Sun Jan 03 18:35:51 2021 +0000
+++ b/usr.bin/xlint/lint1/err.c Sun Jan 03 18:48:37 2021 +0000
@@ -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 @@
}
void
-error(int n, ...)
+(error)(int n, ...)
{
va_list ap;
@@ -502,7 +502,7 @@
}
void
-warning(int n, ...)
+(warning)(int n, ...)
{
va_list ap;
@@ -512,7 +512,7 @@
}
void
-message(int n, ...)
+(message)(int n, ...)
{
va_list ap;
const char *fn;
@@ -535,7 +535,7 @@
* "right"... [perry, 2 Nov 2002]
*/
void
-c99ism(int n, ...)
+(c99ism)(int n, ...)
{
va_list ap;
bool extensions_ok = Sflag || gflag;
@@ -550,7 +550,7 @@
}
void
-gnuism(int n, ...)
+(gnuism)(int n, ...)
{
va_list ap;
diff -r 68233a4a8777 -r 0fe98acca1b2 usr.bin/xlint/lint1/lint1.h
--- a/usr.bin/xlint/lint1/lint1.h Sun Jan 03 18:35:51 2021 +0000
+++ b/usr.bin/xlint/lint1/lint1.h Sun Jan 03 18:48:37 2021 +0000
@@ -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 @@
#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
Home |
Main Index |
Thread Index |
Old Index