aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2022-05-21 11:16:24 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2022-05-21 11:18:40 +0200
commit7d990b119a6249af9a1ef4f3df9957d8975b56b2 (patch)
treefd21e6b95ea88839593466e8c6f4db304f942824
parentc4706aa764f3ae68258ba60be6325a5662900362 (diff)
parentd08822184fe1d4557beca97c2e3599ffc3668e50 (diff)
downloadsparse-7d990b119a6249af9a1ef4f3df9957d8975b56b2.tar.gz
Merge branch 'next-ramsay'
* fix regression disabling the 'memcpy-max-count' check. * warn about a 'case label' on empty statement Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--parse.c5
-rw-r--r--sparse.c2
-rw-r--r--validation/byte-count-max.c28
-rw-r--r--validation/label-positioning.c22
4 files changed, 56 insertions, 1 deletions
diff --git a/parse.c b/parse.c
index bc1c0602..9f2a3cdf 100644
--- a/parse.c
+++ b/parse.c
@@ -2329,6 +2329,11 @@ static inline struct token *case_statement(struct token *token, struct statement
stmt->type = STMT_CASE;
token = expect(token, ':', "after default/case");
add_case_statement(stmt);
+ if (match_op(token, '}')) {
+ warning(token->pos, "statement expected after case label");
+ stmt->case_statement = alloc_statement(token->pos, STMT_NONE);
+ return token;
+ }
return statement(token, &stmt->case_statement);
}
diff --git a/sparse.c b/sparse.c
index 9d62d4fe..e7cc6f55 100644
--- a/sparse.c
+++ b/sparse.c
@@ -165,7 +165,7 @@ static void check_byte_count(struct instruction *insn, pseudo_t count)
static void check_memset(struct instruction *insn)
{
- check_byte_count(insn, ptr_list_nth(insn->arguments, 3));
+ check_byte_count(insn, ptr_list_nth(insn->arguments, 2));
}
#define check_memcpy check_memset
diff --git a/validation/byte-count-max.c b/validation/byte-count-max.c
new file mode 100644
index 00000000..0555a505
--- /dev/null
+++ b/validation/byte-count-max.c
@@ -0,0 +1,28 @@
+typedef unsigned long int size_t;
+typedef unsigned long ulong;
+
+extern void *memset(void *s, int c, size_t n);
+extern void *memcpy(void *dest, void *src, size_t n);
+extern ulong copy_to_user(void *to, const void *from, ulong count);
+extern ulong copy_from_user(void *to, const void *from, ulong count);
+
+static void func (char *s)
+{
+ char d[250000];
+
+ memset(d, 0, 250000);
+ memcpy(d, s, 250000);
+ copy_to_user(s, d, 250000);
+ copy_from_user(d, s, 250000);
+}
+
+/*
+ * check-name: byte-count-max
+ *
+ * check-error-start
+byte-count-max.c:13:15: warning: memset with byte count of 250000
+byte-count-max.c:14:15: warning: memcpy with byte count of 250000
+byte-count-max.c:15:21: warning: copy_to_user with byte count of 250000
+byte-count-max.c:16:23: warning: copy_from_user with byte count of 250000
+ * check-error-end
+ */
diff --git a/validation/label-positioning.c b/validation/label-positioning.c
new file mode 100644
index 00000000..583661ca
--- /dev/null
+++ b/validation/label-positioning.c
@@ -0,0 +1,22 @@
+extern int someval(void);
+
+static void func (int x)
+{
+ if (x > someval())
+ goto end;
+ switch (x) { case 0: }
+ switch (x) { case 1 ... 9: }
+ switch (x) { default: }
+end:
+}
+
+/*
+ * check-name: label-positioning
+ *
+ * check-error-start
+label-positioning.c:7:30: warning: statement expected after case label
+label-positioning.c:8:36: warning: statement expected after case label
+label-positioning.c:9:31: warning: statement expected after case label
+label-positioning.c:11:1: warning: statement expected after label
+ * check-error-end
+ */