aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2017-05-25 15:51:21 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2017-06-15 10:03:49 +0200
commit6081052837c130ef4875a993a8034c9520e4c0ef (patch)
treeb8b38646b409e6bce0a15c20b6335009e3ef1a87
parentd33fdf2c0ad3a296064b592bbcdc2355c4f41dc0 (diff)
downloadsparse-dev-6081052837c130ef4875a993a8034c9520e4c0ef.tar.gz
add support for -Wmemcpy-max-count
sparse will warn if memcpy() (or memset(), copy_from_user(), copy_to_user()) is called with a very large static byte-count. But this warning is given unconditionaly while there are projects where this warning may not be not desired. Change this by making this warning conditional on a new warning flag: -W[no-]memcpy-max-count Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rwxr-xr-xcgcc2
-rw-r--r--lib.c2
-rw-r--r--lib.h1
-rw-r--r--sparse.18
-rw-r--r--sparse.c3
5 files changed, 14 insertions, 2 deletions
diff --git a/cgcc b/cgcc
index 2f2c6cac..b7bad803 100755
--- a/cgcc
+++ b/cgcc
@@ -101,7 +101,7 @@ exit 0;
sub check_only_option {
my ($arg) = @_;
- return 1 if $arg =~ /^-W(no-?)?(address-space|bitwise|cast-to-as|cast-truncate|context|decl|default-bitfield-sign|designated-init|do-while|enum-mismatch|init-cstring|non-pointer-null|old-initializer|one-bit-signed-bitfield|override-init-all|paren-string|ptr-subtraction-blows|return-void|sizeof-bool|sparse-all|sparse-error|transparent-union|typesign|undef|unknown-attribute)$/;
+ return 1 if $arg =~ /^-W(no-?)?(address-space|bitwise|cast-to-as|cast-truncate|context|decl|default-bitfield-sign|designated-init|do-while|enum-mismatch|init-cstring|memcpy-max-count|non-pointer-null|old-initializer|one-bit-signed-bitfield|override-init-all|paren-string|ptr-subtraction-blows|return-void|sizeof-bool|sparse-all|sparse-error|transparent-union|typesign|undef|unknown-attribute)$/;
return 1 if $arg =~ /^-v(no-?)?(entry|dead)$/;
return 1 if $arg =~ /^-f(dump-linearize)(=\S*)?$/;
return 0;
diff --git a/lib.c b/lib.c
index e3901ac9..8bee1bfd 100644
--- a/lib.c
+++ b/lib.c
@@ -230,6 +230,7 @@ int Wdo_while = 0;
int Winit_cstring = 0;
int Wenum_mismatch = 1;
int Wsparse_error = 0;
+int Wmemcpy_max_count = 1;
int Wnon_pointer_null = 1;
int Wold_initializer = 1;
int Wone_bit_signed_bitfield = 1;
@@ -506,6 +507,7 @@ static const struct warning {
{ "do-while", &Wdo_while },
{ "enum-mismatch", &Wenum_mismatch },
{ "init-cstring", &Winit_cstring },
+ { "memcpy-max-count", &Wmemcpy_max_count },
{ "non-pointer-null", &Wnon_pointer_null },
{ "old-initializer", &Wold_initializer },
{ "one-bit-signed-bitfield", &Wone_bit_signed_bitfield },
diff --git a/lib.h b/lib.h
index 3c08f1c3..da5307f7 100644
--- a/lib.h
+++ b/lib.h
@@ -120,6 +120,7 @@ extern int Wdo_while;
extern int Wenum_mismatch;
extern int Wsparse_error;
extern int Winit_cstring;
+extern int Wmemcpy_max_count;
extern int Wnon_pointer_null;
extern int Wold_initializer;
extern int Wone_bit_signed_bitfield;
diff --git a/sparse.1 b/sparse.1
index c924b3a5..df3c7f44 100644
--- a/sparse.1
+++ b/sparse.1
@@ -210,6 +210,14 @@ trouble.
Sparse does not issue these warnings by default.
.
.TP
+.B \-Wmemcpy\-max\-count
+Warn about call of \fBmemcpy()\fR, \fBmemset()\fR, \fBcopy_from_user()\fR, or
+\fBcopy_to_user()\fR with a large compile-time byte count.
+
+Sparse issues these warnings by default. To turn them off, use
+\fB\-Wno\-memcpy\-max\-count\fR.
+.
+.TP
.B \-Wnon\-pointer\-null
Warn about the use of 0 as a NULL pointer.
diff --git a/sparse.c b/sparse.c
index 1cb90e20..aa5979f1 100644
--- a/sparse.c
+++ b/sparse.c
@@ -153,7 +153,8 @@ static void check_byte_count(struct instruction *insn, pseudo_t count)
return;
if (count->type == PSEUDO_VAL) {
unsigned long long val = count->value;
- if (val > 100000ULL)
+ if (Wmemcpy_max_count && val > 100000ULL)
+
warning(insn->pos, "%s with byte count of %llu",
show_ident(insn->func->sym->ident), val);
return;