[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-trivial] [PATCH v2 1/5] scripts: add muldiv64() checking coccinell
From: |
Laurent Vivier |
Subject: |
[Qemu-trivial] [PATCH v2 1/5] scripts: add muldiv64() checking coccinelle scripts |
Date: |
Mon, 9 May 2016 15:24:55 +0200 |
Signed-off-by: Laurent Vivier <address@hidden>
---
scripts/coccinelle/overflow_muldiv64.cocci | 16 ++++++++++++++++
scripts/coccinelle/remove_muldiv64.cocci | 6 ++++++
scripts/coccinelle/simplify_muldiv64.cocci | 11 +++++++++++
scripts/coccinelle/swap_muldiv64.cocci | 13 +++++++++++++
4 files changed, 46 insertions(+)
create mode 100644 scripts/coccinelle/overflow_muldiv64.cocci
create mode 100644 scripts/coccinelle/remove_muldiv64.cocci
create mode 100644 scripts/coccinelle/simplify_muldiv64.cocci
create mode 100644 scripts/coccinelle/swap_muldiv64.cocci
diff --git a/scripts/coccinelle/overflow_muldiv64.cocci
b/scripts/coccinelle/overflow_muldiv64.cocci
new file mode 100644
index 0000000..08ec4a8
--- /dev/null
+++ b/scripts/coccinelle/overflow_muldiv64.cocci
@@ -0,0 +1,16 @@
+// Find muldiv64(i64, i64, x) for potential overflow
address@hidden@
+typedef uint64_t;
+typedef int64_t;
+{ uint64_t, int64_t, long, unsigned long } a, b;
+expression c;
+position p;
+@@
+
+muldiv64(a,b,c)@p
+
address@hidden: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 0000000..4c10bd5
--- /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 0000000..3d7c974
--- /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 0000000..b48b0d0
--- /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)
--
2.5.5
- [Qemu-trivial] [PATCH v2 0/5] muldiv64() trivial fixes, Laurent Vivier, 2016/05/09
- [Qemu-trivial] [PATCH v2 1/5] scripts: add muldiv64() checking coccinelle scripts,
Laurent Vivier <=
- [Qemu-trivial] [PATCH v2 2/5] The only 64bit parameter of muldiv64() is the first one., Laurent Vivier, 2016/05/09
- [Qemu-trivial] [PATCH v2 3/5] remove useless muldiv64(), Laurent Vivier, 2016/05/09
- [Qemu-trivial] [PATCH v2 4/5] replace muldiv64(a, b, c) by (uint64_t)a * b / c, Laurent Vivier, 2016/05/09
- [Qemu-trivial] [PATCH v2 5/5] ppc: Remove a potential overflow in muldiv64(), Laurent Vivier, 2016/05/09
- Re: [Qemu-trivial] [PATCH v2 0/5] muldiv64() trivial fixes, Michael Tokarev, 2016/05/29