The function check_access() verify that memory accesses are not done out of their bounds. This is good. However, this function is called at each run of simplify_loads() which means that the same warning can be given multiple times which is annoying. Fix this by using the newly added 'tainted' field to not warn a second time on this instruction. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx> --- flow.c | 6 +++++- validation/check_access-multi.c | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 validation/check_access-multi.c diff --git a/flow.c b/flow.c index b6412461b..b28d2e408 100644 --- a/flow.c +++ b/flow.c @@ -646,11 +646,15 @@ void check_access(struct instruction *insn) int offset = insn->offset, bit = bytes_to_bits(offset) + insn->size; struct symbol *sym = pseudo->sym; - if (sym->bit_size > 0 && (offset < 0 || bit > sym->bit_size)) + if (sym->bit_size > 0 && (offset < 0 || bit > sym->bit_size)) { + if (insn->tainted) + return; warning(insn->pos, "invalid access %s '%s' (%d %d)", offset < 0 ? "below" : "past the end of", show_ident(sym->ident), offset, bits_to_bytes(sym->bit_size)); + insn->tainted = 1; + } } } diff --git a/validation/check_access-multi.c b/validation/check_access-multi.c new file mode 100644 index 000000000..5d6c6ce30 --- /dev/null +++ b/validation/check_access-multi.c @@ -0,0 +1,15 @@ +extern long *a; +extern long b[1]; + +static void foo(void) +{ + *a = b[1]; +} + +/* + * check-name: check_access-multi + * + * check-error-start +check_access-multi.c:6:15: warning: invalid access past the end of 'b' (8 8) + * check-error-end + */ -- 2.16.2 -- To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html