Module Name: src
Committed By: christos
Date: Thu Jan 14 16:58:27 UTC 2010
Modified Files:
src/usr.bin/xlint/lint2: chk.c main2.c
Log Message:
Add a list of functions where we usually don't care about their return
code. Can be bypassed by -hh
To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/usr.bin/xlint/lint2/chk.c
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/xlint/lint2/main2.c
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/lint2/chk.c
diff -u src/usr.bin/xlint/lint2/chk.c:1.20 src/usr.bin/xlint/lint2/chk.c:1.21
--- src/usr.bin/xlint/lint2/chk.c:1.20 Tue Apr 14 05:03:45 2009
+++ src/usr.bin/xlint/lint2/chk.c Thu Jan 14 11:58:27 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: chk.c,v 1.20 2009/04/14 09:03:45 lukem Exp $ */
+/* $NetBSD: chk.c,v 1.21 2010/01/14 16:58:27 christos Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -38,10 +38,11 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: chk.c,v 1.20 2009/04/14 09:03:45 lukem Exp $");
+__RCSID("$NetBSD: chk.c,v 1.21 2010/01/14 16:58:27 christos Exp $");
#endif
#include <ctype.h>
+#include <string.h>
#include <limits.h>
#include <stdlib.h>
@@ -1045,6 +1046,19 @@
msg(16, hte->h_name, mkpos(&call->f_pos));
}
+/*
+ * List of functions where we usually don't care about their result.
+ * NB: Must be sorted.
+ */
+static const char ignorelist[][8] = {
+ "memcpy",
+ "memmove",
+ "memset",
+ "printf",
+ "strcat",
+ "strcpy",
+ "vprintf",
+};
/*
* Print warnings for return values which are used, but not returned,
@@ -1064,26 +1078,31 @@
return;
if (def->s_rval) {
- /* function has return value */
- used = ignored = 0;
- for (call = hte->h_calls; call != NULL; call = call->f_nxt) {
- used |= call->f_rused || call->f_rdisc;
- ignored |= !call->f_rused && !call->f_rdisc;
- }
/*
* XXX as soon as we are able to disable single warnings
* the following dependencies from hflag should be removed.
* but for now I do'nt want to be botherd by this warnings
* which are almost always useless.
*/
+ if (hflag == 0)
+ return;
+ if (hflag == 1 && bsearch(hte->h_name, ignorelist,
+ __arraycount(ignorelist), sizeof(ignorelist[0]),
+ (int (*)(const void *, const void *))strcmp) != NULL)
+ return;
+
+ /* function has return value */
+ used = ignored = 0;
+ for (call = hte->h_calls; call != NULL; call = call->f_nxt) {
+ used |= call->f_rused || call->f_rdisc;
+ ignored |= !call->f_rused && !call->f_rdisc;
+ }
if (!used && ignored) {
- if (hflag)
- /* %s returns value which is always ignored */
- msg(8, hte->h_name);
+ /* %s returns value which is always ignored */
+ msg(8, hte->h_name);
} else if (used && ignored) {
- if (hflag)
- /* %s returns value which is sometimes ign. */
- msg(9, hte->h_name);
+ /* %s returns value which is sometimes ign. */
+ msg(9, hte->h_name);
}
} else {
/* function has no return value */
Index: src/usr.bin/xlint/lint2/main2.c
diff -u src/usr.bin/xlint/lint2/main2.c:1.7 src/usr.bin/xlint/lint2/main2.c:1.8
--- src/usr.bin/xlint/lint2/main2.c:1.7 Sun Jun 20 18:20:17 2004
+++ src/usr.bin/xlint/lint2/main2.c Thu Jan 14 11:58:27 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: main2.c,v 1.7 2004/06/20 22:20:17 jmc Exp $ */
+/* $NetBSD: main2.c,v 1.8 2010/01/14 16:58:27 christos Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: main2.c,v 1.7 2004/06/20 22:20:17 jmc Exp $");
+__RCSID("$NetBSD: main2.c,v 1.8 2010/01/14 16:58:27 christos Exp $");
#endif
#include <stdio.h>
@@ -131,7 +131,7 @@
Hflag = 1;
break;
case 'h':
- hflag = 1;
+ hflag++;
break;
case 'F':
Fflag = 1;