diff options
author | Laurent Vivier | 2016-05-09 15:24:55 +0200 |
---|---|---|
committer | Michael Tokarev | 2016-06-07 17:02:49 +0200 |
commit | e9d5150739c4e321088eddfe46b88a8654d86eae (patch) | |
tree | 9a47ab91710c6f160a534dffdeb00d9c18e872ad /scripts | |
parent | gdbstub: set listen backlog to 1 (diff) | |
download | qemu-e9d5150739c4e321088eddfe46b88a8654d86eae.tar.gz qemu-e9d5150739c4e321088eddfe46b88a8654d86eae.tar.xz qemu-e9d5150739c4e321088eddfe46b88a8654d86eae.zip |
scripts: add muldiv64() checking coccinelle scripts
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/coccinelle/overflow_muldiv64.cocci | 16 | ||||
-rw-r--r-- | scripts/coccinelle/remove_muldiv64.cocci | 6 | ||||
-rw-r--r-- | scripts/coccinelle/simplify_muldiv64.cocci | 11 | ||||
-rw-r--r-- | scripts/coccinelle/swap_muldiv64.cocci | 13 |
4 files changed, 46 insertions, 0 deletions
diff --git a/scripts/coccinelle/overflow_muldiv64.cocci b/scripts/coccinelle/overflow_muldiv64.cocci new file mode 100644 index 0000000000..08ec4a8de0 --- /dev/null +++ b/scripts/coccinelle/overflow_muldiv64.cocci @@ -0,0 +1,16 @@ +// Find muldiv64(i64, i64, x) for potential overflow +@filter@ +typedef uint64_t; +typedef int64_t; +{ uint64_t, int64_t, long, unsigned long } a, b; +expression c; +position p; +@@ + +muldiv64(a,b,c)@p + +@script:python@ +p << filter.p; +@@ + +cocci.print_main("potential muldiv64() overflow", p) diff --git a/scripts/coccinelle/remove_muldiv64.cocci b/scripts/coccinelle/remove_muldiv64.cocci new file mode 100644 index 0000000000..4c10bd57dd --- /dev/null +++ b/scripts/coccinelle/remove_muldiv64.cocci @@ -0,0 +1,6 @@ +// replace muldiv64(a, 1, b) by "a / b" +@@ +expression a, b; +@@ +-muldiv64(a, 1, b) ++a / b diff --git a/scripts/coccinelle/simplify_muldiv64.cocci b/scripts/coccinelle/simplify_muldiv64.cocci new file mode 100644 index 0000000000..3d7c9744aa --- /dev/null +++ b/scripts/coccinelle/simplify_muldiv64.cocci @@ -0,0 +1,11 @@ +// replace muldiv64(i32, i32, x) by (uint64_t)i32 * i32 / x +@@ +typedef uint32_t; +typedef int32_t; +{ uint32_t, int32_t, int, unsigned int } a, b; +typedef uint64_t; +expression c; +@@ + +-muldiv64(a,b,c) ++(uint64_t) a * b / c diff --git a/scripts/coccinelle/swap_muldiv64.cocci b/scripts/coccinelle/swap_muldiv64.cocci new file mode 100644 index 0000000000..b48b0d084a --- /dev/null +++ b/scripts/coccinelle/swap_muldiv64.cocci @@ -0,0 +1,13 @@ +// replace muldiv64(i32, i64, x) by muldiv64(i64, i32, x) +@@ +typedef uint64_t; +typedef int64_t; +typedef uint32_t; +typedef int32_t; +{ uint32_t, int32_t, int, unsigned int } a; +{ uint64_t, int64_t, long, unsigned long } b; +expression c; +@@ + +-muldiv64(a,b,c) ++muldiv64(b,a,c) |