* [PATCH v2] coccinelle: assign signed result to unsigned variable
@ 2015-09-28 10:54 ` Andrzej Hajda
0 siblings, 0 replies; 89+ messages in thread
From: Andrzej Hajda @ 2015-09-28 10:54 UTC (permalink / raw)
To: julia.lawall
Cc: Andrzej Hajda, Bartlomiej Zolnierkiewicz, Marek Szyprowski,
Gilles Muller, Michal Marek, Nicolas Palix, kernel-janitors,
linux-kernel, cocci, elfring
Assigning signed function result to unsigned variable can indicate error.
To decrease number of false positives patch looks if after assignment
there is also check for negative values of the result.
Signed-off-by: Andrzej Hajda <a.hajda@samsung.com>
---
Hi Julia,
Thanks for the hint. Now it looks much better.
Summarizing this patch has found 20 problems and has 22 false positives [1][2].
unsigned_lesser_than_zero.cocci patch posted earlier has found
40 problems [3][4], and about 80 false positives if I remember correctly.
Few patches were rejected, as developers likes code for testing variable range,
even if its result is always true/false [5][6], but most of kernel patches are
real bug fixes.
Both patches tries to address similar issues, maybe it would be good to merge
them? Especially as their results overlap.
Additionally I thought about adding detecting range checks in
unsigned_lesser_than_zero.cocci, to decrease number of false positives.
Of course it could then miss real bugs. What do you think about it?
[1]: http://permalink.gmane.org/gmane.linux.kernel/2046131
[2]: http://permalink.gmane.org/gmane.linux.kernel/2048070
[3]: http://permalink.gmane.org/gmane.comp.freedesktop.xorg.drivers.intel/70031
[4]: http://permalink.gmane.org/gmane.linux.power-management.general/66143
[5]: http://permalink.gmane.org/gmane.linux.kernel.mm/138902
[6]: http://libdivecomputer.org/pipermail/devel/2014-July/000329.html
Regards
Andrzej
---
.../tests/assign_signed_to_unsigned.cocci | 45 ++++++++++++++++++++++
1 file changed, 45 insertions(+)
create mode 100644 scripts/coccinelle/tests/assign_signed_to_unsigned.cocci
diff --git a/scripts/coccinelle/tests/assign_signed_to_unsigned.cocci b/scripts/coccinelle/tests/assign_signed_to_unsigned.cocci
new file mode 100644
index 0000000..efa4e83
--- /dev/null
+++ b/scripts/coccinelle/tests/assign_signed_to_unsigned.cocci
@@ -0,0 +1,45 @@
+/// Assigning signed function result to unsigned variable can indicate error.
+/// To decrease number of false positives patch looks if after assignment
+/// there is also check for negative values of the result.
+///
+// Confidence: High
+// Copyright: (C) 2015 Andrzej Hajda, Samsung Electronics Co., Ltd. GPLv2.
+// URL: http://coccinelle.lip6.fr/
+// Options: --include-headers --all-includes
+
+virtual context
+virtual org
+virtual report
+
+@r@
+typedef bool, u8, u16, u32, u64, s8, s16, s32, s64;
+{char, short, int, long, long long, s8, s16, s32, s64} vs;
+{unsigned char, unsigned short, unsigned int, unsigned long, unsigned long long,
+ size_t, bool, u8, u16, u32, u64} vu;
+position p;
+identifier f;
+statement S1, S2;
+expression e;
+@@
+
+*vu@p = f(...)@vs;
+... when != vu = e;
+if ( \( vu < 0 \| vu <= 0 \) ) S1 else S2
+
+@script:python depends on r && org@
+p << r.p;
+f << r.f;
+vu << r.vu;
+@@
+
+msg = "WARNING: Assigning signed result to unsigned variable: %s = %s(...)" % (vu, f)
+coccilib.org.print_todo(p[0], msg)
+
+@script:python depends on r && report@
+p << r.p;
+f << r.f;
+vu << r.vu;
+@@
+
+msg = "WARNING: Assigning signed result to unsigned variable: %s = %s(...)" % (vu, f)
+coccilib.report.print_report(p[0], msg)
--
1.9.1
^ permalink raw reply related [flat|nested] 89+ messages in thread* [PATCH v2] coccinelle: assign signed result to unsigned variable
@ 2015-09-28 10:54 ` Andrzej Hajda
0 siblings, 0 replies; 89+ messages in thread
From: Andrzej Hajda @ 2015-09-28 10:54 UTC (permalink / raw)
To: cocci
Assigning signed function result to unsigned variable can indicate error.
To decrease number of false positives patch looks if after assignment
there is also check for negative values of the result.
Signed-off-by: Andrzej Hajda <a.hajda@samsung.com>
---
Hi Julia,
Thanks for the hint. Now it looks much better.
Summarizing this patch has found 20 problems and has 22 false positives [1][2].
unsigned_lesser_than_zero.cocci patch posted earlier has found
40 problems [3][4], and about 80 false positives if I remember correctly.
Few patches were rejected, as developers likes code for testing variable range,
even if its result is always true/false [5][6], but most of kernel patches are
real bug fixes.
Both patches tries to address similar issues, maybe it would be good to merge
them? Especially as their results overlap.
Additionally I thought about adding detecting range checks in
unsigned_lesser_than_zero.cocci, to decrease number of false positives.
Of course it could then miss real bugs. What do you think about it?
[1]: http://permalink.gmane.org/gmane.linux.kernel/2046131
[2]: http://permalink.gmane.org/gmane.linux.kernel/2048070
[3]: http://permalink.gmane.org/gmane.comp.freedesktop.xorg.drivers.intel/70031
[4]: http://permalink.gmane.org/gmane.linux.power-management.general/66143
[5]: http://permalink.gmane.org/gmane.linux.kernel.mm/138902
[6]: http://libdivecomputer.org/pipermail/devel/2014-July/000329.html
Regards
Andrzej
---
.../tests/assign_signed_to_unsigned.cocci | 45 ++++++++++++++++++++++
1 file changed, 45 insertions(+)
create mode 100644 scripts/coccinelle/tests/assign_signed_to_unsigned.cocci
diff --git a/scripts/coccinelle/tests/assign_signed_to_unsigned.cocci b/scripts/coccinelle/tests/assign_signed_to_unsigned.cocci
new file mode 100644
index 0000000..efa4e83
--- /dev/null
+++ b/scripts/coccinelle/tests/assign_signed_to_unsigned.cocci
@@ -0,0 +1,45 @@
+/// Assigning signed function result to unsigned variable can indicate error.
+/// To decrease number of false positives patch looks if after assignment
+/// there is also check for negative values of the result.
+///
+// Confidence: High
+// Copyright: (C) 2015 Andrzej Hajda, Samsung Electronics Co., Ltd. GPLv2.
+// URL: http://coccinelle.lip6.fr/
+// Options: --include-headers --all-includes
+
+virtual context
+virtual org
+virtual report
+
+@r@
+typedef bool, u8, u16, u32, u64, s8, s16, s32, s64;
+{char, short, int, long, long long, s8, s16, s32, s64} vs;
+{unsigned char, unsigned short, unsigned int, unsigned long, unsigned long long,
+ size_t, bool, u8, u16, u32, u64} vu;
+position p;
+identifier f;
+statement S1, S2;
+expression e;
+@@
+
+*vu@p = f(...)@vs;
+... when != vu = e;
+if ( \( vu < 0 \| vu <= 0 \) ) S1 else S2
+
+@script:python depends on r && org@
+p << r.p;
+f << r.f;
+vu << r.vu;
+@@
+
+msg = "WARNING: Assigning signed result to unsigned variable: %s = %s(...)" % (vu, f)
+coccilib.org.print_todo(p[0], msg)
+
+@script:python depends on r && report@
+p << r.p;
+f << r.f;
+vu << r.vu;
+@@
+
+msg = "WARNING: Assigning signed result to unsigned variable: %s = %s(...)" % (vu, f)
+coccilib.report.print_report(p[0], msg)
--
1.9.1
^ permalink raw reply related [flat|nested] 89+ messages in thread* [Cocci] [PATCH v2] coccinelle: assign signed result to unsigned variable
2015-09-28 10:54 ` Andrzej Hajda
(?)
@ 2015-09-28 11:32 ` Julia Lawall
-1 siblings, 0 replies; 89+ messages in thread
From: Julia Lawall @ 2015-09-28 11:32 UTC (permalink / raw)
To: cocci
On Mon, 28 Sep 2015, Andrzej Hajda wrote:
> Assigning signed function result to unsigned variable can indicate error.
> To decrease number of false positives patch looks if after assignment
> there is also check for negative values of the result.
>
> Signed-off-by: Andrzej Hajda <a.hajda@samsung.com>
> ---
> Hi Julia,
>
> Thanks for the hint. Now it looks much better.
> Summarizing this patch has found 20 problems and has 22 false positives [1][2].
Do you have some examples of the false positives?
julia
> unsigned_lesser_than_zero.cocci patch posted earlier has found
> 40 problems [3][4], and about 80 false positives if I remember correctly.
> Few patches were rejected, as developers likes code for testing variable range,
> even if its result is always true/false [5][6], but most of kernel patches are
> real bug fixes.
>
> Both patches tries to address similar issues, maybe it would be good to merge
> them? Especially as their results overlap.
> Additionally I thought about adding detecting range checks in
> unsigned_lesser_than_zero.cocci, to decrease number of false positives.
> Of course it could then miss real bugs. What do you think about it?
>
> [1]: http://permalink.gmane.org/gmane.linux.kernel/2046131
> [2]: http://permalink.gmane.org/gmane.linux.kernel/2048070
> [3]: http://permalink.gmane.org/gmane.comp.freedesktop.xorg.drivers.intel/70031
> [4]: http://permalink.gmane.org/gmane.linux.power-management.general/66143
> [5]: http://permalink.gmane.org/gmane.linux.kernel.mm/138902
> [6]: http://libdivecomputer.org/pipermail/devel/2014-July/000329.html
>
> Regards
> Andrzej
>
> ---
> .../tests/assign_signed_to_unsigned.cocci | 45 ++++++++++++++++++++++
> 1 file changed, 45 insertions(+)
> create mode 100644 scripts/coccinelle/tests/assign_signed_to_unsigned.cocci
>
> diff --git a/scripts/coccinelle/tests/assign_signed_to_unsigned.cocci b/scripts/coccinelle/tests/assign_signed_to_unsigned.cocci
> new file mode 100644
> index 0000000..efa4e83
> --- /dev/null
> +++ b/scripts/coccinelle/tests/assign_signed_to_unsigned.cocci
> @@ -0,0 +1,45 @@
> +/// Assigning signed function result to unsigned variable can indicate error.
> +/// To decrease number of false positives patch looks if after assignment
> +/// there is also check for negative values of the result.
> +///
> +// Confidence: High
> +// Copyright: (C) 2015 Andrzej Hajda, Samsung Electronics Co., Ltd. GPLv2.
> +// URL: http://coccinelle.lip6.fr/
> +// Options: --include-headers --all-includes
> +
> +virtual context
> +virtual org
> +virtual report
> +
> + at r@
> +typedef bool, u8, u16, u32, u64, s8, s16, s32, s64;
> +{char, short, int, long, long long, s8, s16, s32, s64} vs;
> +{unsigned char, unsigned short, unsigned int, unsigned long, unsigned long long,
> + size_t, bool, u8, u16, u32, u64} vu;
> +position p;
> +identifier f;
> +statement S1, S2;
> +expression e;
> +@@
> +
> +*vu at p = f(...)@vs;
> +... when != vu = e;
> +if ( \( vu < 0 \| vu <= 0 \) ) S1 else S2
> +
> + at script:python depends on r && org@
> +p << r.p;
> +f << r.f;
> +vu << r.vu;
> +@@
> +
> +msg = "WARNING: Assigning signed result to unsigned variable: %s = %s(...)" % (vu, f)
> +coccilib.org.print_todo(p[0], msg)
> +
> + at script:python depends on r && report@
> +p << r.p;
> +f << r.f;
> +vu << r.vu;
> +@@
> +
> +msg = "WARNING: Assigning signed result to unsigned variable: %s = %s(...)" % (vu, f)
> +coccilib.report.print_report(p[0], msg)
> --
> 1.9.1
>
>
^ permalink raw reply [flat|nested] 89+ messages in thread* Re: [PATCH v2] coccinelle: assign signed result to unsigned variable
@ 2015-09-28 11:32 ` Julia Lawall
0 siblings, 0 replies; 89+ messages in thread
From: Julia Lawall @ 2015-09-28 11:32 UTC (permalink / raw)
To: Andrzej Hajda
Cc: julia.lawall, Bartlomiej Zolnierkiewicz, Marek Szyprowski,
Gilles Muller, Michal Marek, Nicolas Palix, kernel-janitors,
linux-kernel, cocci, elfring
On Mon, 28 Sep 2015, Andrzej Hajda wrote:
> Assigning signed function result to unsigned variable can indicate error.
> To decrease number of false positives patch looks if after assignment
> there is also check for negative values of the result.
>
> Signed-off-by: Andrzej Hajda <a.hajda@samsung.com>
> ---
> Hi Julia,
>
> Thanks for the hint. Now it looks much better.
> Summarizing this patch has found 20 problems and has 22 false positives [1][2].
Do you have some examples of the false positives?
julia
> unsigned_lesser_than_zero.cocci patch posted earlier has found
> 40 problems [3][4], and about 80 false positives if I remember correctly.
> Few patches were rejected, as developers likes code for testing variable range,
> even if its result is always true/false [5][6], but most of kernel patches are
> real bug fixes.
>
> Both patches tries to address similar issues, maybe it would be good to merge
> them? Especially as their results overlap.
> Additionally I thought about adding detecting range checks in
> unsigned_lesser_than_zero.cocci, to decrease number of false positives.
> Of course it could then miss real bugs. What do you think about it?
>
> [1]: http://permalink.gmane.org/gmane.linux.kernel/2046131
> [2]: http://permalink.gmane.org/gmane.linux.kernel/2048070
> [3]: http://permalink.gmane.org/gmane.comp.freedesktop.xorg.drivers.intel/70031
> [4]: http://permalink.gmane.org/gmane.linux.power-management.general/66143
> [5]: http://permalink.gmane.org/gmane.linux.kernel.mm/138902
> [6]: http://libdivecomputer.org/pipermail/devel/2014-July/000329.html
>
> Regards
> Andrzej
>
> ---
> .../tests/assign_signed_to_unsigned.cocci | 45 ++++++++++++++++++++++
> 1 file changed, 45 insertions(+)
> create mode 100644 scripts/coccinelle/tests/assign_signed_to_unsigned.cocci
>
> diff --git a/scripts/coccinelle/tests/assign_signed_to_unsigned.cocci b/scripts/coccinelle/tests/assign_signed_to_unsigned.cocci
> new file mode 100644
> index 0000000..efa4e83
> --- /dev/null
> +++ b/scripts/coccinelle/tests/assign_signed_to_unsigned.cocci
> @@ -0,0 +1,45 @@
> +/// Assigning signed function result to unsigned variable can indicate error.
> +/// To decrease number of false positives patch looks if after assignment
> +/// there is also check for negative values of the result.
> +///
> +// Confidence: High
> +// Copyright: (C) 2015 Andrzej Hajda, Samsung Electronics Co., Ltd. GPLv2.
> +// URL: http://coccinelle.lip6.fr/
> +// Options: --include-headers --all-includes
> +
> +virtual context
> +virtual org
> +virtual report
> +
> +@r@
> +typedef bool, u8, u16, u32, u64, s8, s16, s32, s64;
> +{char, short, int, long, long long, s8, s16, s32, s64} vs;
> +{unsigned char, unsigned short, unsigned int, unsigned long, unsigned long long,
> + size_t, bool, u8, u16, u32, u64} vu;
> +position p;
> +identifier f;
> +statement S1, S2;
> +expression e;
> +@@
> +
> +*vu@p = f(...)@vs;
> +... when != vu = e;
> +if ( \( vu < 0 \| vu <= 0 \) ) S1 else S2
> +
> +@script:python depends on r && org@
> +p << r.p;
> +f << r.f;
> +vu << r.vu;
> +@@
> +
> +msg = "WARNING: Assigning signed result to unsigned variable: %s = %s(...)" % (vu, f)
> +coccilib.org.print_todo(p[0], msg)
> +
> +@script:python depends on r && report@
> +p << r.p;
> +f << r.f;
> +vu << r.vu;
> +@@
> +
> +msg = "WARNING: Assigning signed result to unsigned variable: %s = %s(...)" % (vu, f)
> +coccilib.report.print_report(p[0], msg)
> --
> 1.9.1
>
>
^ permalink raw reply [flat|nested] 89+ messages in thread* Re: [PATCH v2] coccinelle: assign signed result to unsigned variable
@ 2015-09-28 11:32 ` Julia Lawall
0 siblings, 0 replies; 89+ messages in thread
From: Julia Lawall @ 2015-09-28 11:32 UTC (permalink / raw)
To: cocci
On Mon, 28 Sep 2015, Andrzej Hajda wrote:
> Assigning signed function result to unsigned variable can indicate error.
> To decrease number of false positives patch looks if after assignment
> there is also check for negative values of the result.
>
> Signed-off-by: Andrzej Hajda <a.hajda@samsung.com>
> ---
> Hi Julia,
>
> Thanks for the hint. Now it looks much better.
> Summarizing this patch has found 20 problems and has 22 false positives [1][2].
Do you have some examples of the false positives?
julia
> unsigned_lesser_than_zero.cocci patch posted earlier has found
> 40 problems [3][4], and about 80 false positives if I remember correctly.
> Few patches were rejected, as developers likes code for testing variable range,
> even if its result is always true/false [5][6], but most of kernel patches are
> real bug fixes.
>
> Both patches tries to address similar issues, maybe it would be good to merge
> them? Especially as their results overlap.
> Additionally I thought about adding detecting range checks in
> unsigned_lesser_than_zero.cocci, to decrease number of false positives.
> Of course it could then miss real bugs. What do you think about it?
>
> [1]: http://permalink.gmane.org/gmane.linux.kernel/2046131
> [2]: http://permalink.gmane.org/gmane.linux.kernel/2048070
> [3]: http://permalink.gmane.org/gmane.comp.freedesktop.xorg.drivers.intel/70031
> [4]: http://permalink.gmane.org/gmane.linux.power-management.general/66143
> [5]: http://permalink.gmane.org/gmane.linux.kernel.mm/138902
> [6]: http://libdivecomputer.org/pipermail/devel/2014-July/000329.html
>
> Regards
> Andrzej
>
> ---
> .../tests/assign_signed_to_unsigned.cocci | 45 ++++++++++++++++++++++
> 1 file changed, 45 insertions(+)
> create mode 100644 scripts/coccinelle/tests/assign_signed_to_unsigned.cocci
>
> diff --git a/scripts/coccinelle/tests/assign_signed_to_unsigned.cocci b/scripts/coccinelle/tests/assign_signed_to_unsigned.cocci
> new file mode 100644
> index 0000000..efa4e83
> --- /dev/null
> +++ b/scripts/coccinelle/tests/assign_signed_to_unsigned.cocci
> @@ -0,0 +1,45 @@
> +/// Assigning signed function result to unsigned variable can indicate error.
> +/// To decrease number of false positives patch looks if after assignment
> +/// there is also check for negative values of the result.
> +///
> +// Confidence: High
> +// Copyright: (C) 2015 Andrzej Hajda, Samsung Electronics Co., Ltd. GPLv2.
> +// URL: http://coccinelle.lip6.fr/
> +// Options: --include-headers --all-includes
> +
> +virtual context
> +virtual org
> +virtual report
> +
> +@r@
> +typedef bool, u8, u16, u32, u64, s8, s16, s32, s64;
> +{char, short, int, long, long long, s8, s16, s32, s64} vs;
> +{unsigned char, unsigned short, unsigned int, unsigned long, unsigned long long,
> + size_t, bool, u8, u16, u32, u64} vu;
> +position p;
> +identifier f;
> +statement S1, S2;
> +expression e;
> +@@
> +
> +*vu@p = f(...)@vs;
> +... when != vu = e;
> +if ( \( vu < 0 \| vu <= 0 \) ) S1 else S2
> +
> +@script:python depends on r && org@
> +p << r.p;
> +f << r.f;
> +vu << r.vu;
> +@@
> +
> +msg = "WARNING: Assigning signed result to unsigned variable: %s = %s(...)" % (vu, f)
> +coccilib.org.print_todo(p[0], msg)
> +
> +@script:python depends on r && report@
> +p << r.p;
> +f << r.f;
> +vu << r.vu;
> +@@
> +
> +msg = "WARNING: Assigning signed result to unsigned variable: %s = %s(...)" % (vu, f)
> +coccilib.report.print_report(p[0], msg)
> --
> 1.9.1
>
>
^ permalink raw reply [flat|nested] 89+ messages in thread* [Cocci] [PATCH v2] coccinelle: assign signed result to unsigned variable
2015-09-28 11:32 ` Julia Lawall
(?)
@ 2015-09-28 11:59 ` Andrzej Hajda
-1 siblings, 0 replies; 89+ messages in thread
From: Andrzej Hajda @ 2015-09-28 11:59 UTC (permalink / raw)
To: cocci
On 09/28/2015 01:32 PM, Julia Lawall wrote:
>
> On Mon, 28 Sep 2015, Andrzej Hajda wrote:
>
>> Assigning signed function result to unsigned variable can indicate error.
>> To decrease number of false positives patch looks if after assignment
>> there is also check for negative values of the result.
>>
>> Signed-off-by: Andrzej Hajda <a.hajda@samsung.com>
>> ---
>> Hi Julia,
>>
>> Thanks for the hint. Now it looks much better.
>> Summarizing this patch has found 20 problems and has 22 false positives [1][2].
> Do you have some examples of the false positives?
./drivers/acpi/acpica/nsarguments.c:130:1: WARNING: Assigning signed result to
unsigned variable: required_param_count = METHOD_GET_ARG_COUNT(...)
./drivers/char/agp/intel-gtt.c:361:3: WARNING: Assigning signed result to
unsigned variable: stolen_size = KB(...)
./drivers/char/agp/intel-gtt.c:364:3: WARNING: Assigning signed result to
unsigned variable: stolen_size = MB(...)
./drivers/char/agp/intel-gtt.c:367:3: WARNING: Assigning signed result to
unsigned variable: stolen_size = MB(...)
./drivers/char/agp/intel-gtt.c:382:3: WARNING: Assigning signed result to
unsigned variable: stolen_size = MB(...)
./drivers/char/agp/intel-gtt.c:385:3: WARNING: Assigning signed result to
unsigned variable: stolen_size = MB(...)
./drivers/char/agp/intel-gtt.c:388:3: WARNING: Assigning signed result to
unsigned variable: stolen_size = MB(...)
./drivers/char/agp/intel-gtt.c:391:3: WARNING: Assigning signed result to
unsigned variable: stolen_size = MB(...)
./drivers/char/agp/intel-gtt.c:394:3: WARNING: Assigning signed result to
unsigned variable: stolen_size = MB(...)
./drivers/char/agp/intel-gtt.c:397:3: WARNING: Assigning signed result to
unsigned variable: stolen_size = MB(...)
./drivers/char/agp/intel-gtt.c:400:3: WARNING: Assigning signed result to
unsigned variable: stolen_size = MB(...)
./drivers/char/agp/intel-gtt.c:403:3: WARNING: Assigning signed result to
unsigned variable: stolen_size = MB(...)
./drivers/char/agp/intel-gtt.c:406:3: WARNING: Assigning signed result to
unsigned variable: stolen_size = MB(...)
./drivers/char/agp/intel-gtt.c:409:3: WARNING: Assigning signed result to
unsigned variable: stolen_size = MB(...)
./drivers/char/agp/intel-gtt.c:412:3: WARNING: Assigning signed result to
unsigned variable: stolen_size = MB(...)
./drivers/char/agp/intel-gtt.c:415:3: WARNING: Assigning signed result to
unsigned variable: stolen_size = MB(...)
./drivers/char/agp/intel-gtt.c:418:3: WARNING: Assigning signed result to
unsigned variable: stolen_size = MB(...)
./drivers/input/touchscreen/cyttsp4_core.c:967:1: WARNING: Assigning signed
result to unsigned variable: num_cur_tch = GET_NUM_TOUCHES(...)
./drivers/pinctrl/freescale/pinctrl-imx.c:648:2: WARNING: Assigning signed
result to unsigned variable: nfuncs = of_get_child_count(...)
./fs/btrfs/file.c:1572:2: WARNING: Assigning signed result to unsigned variable:
copied = btrfs_copy_from_user(...)
./fs/xfs/libxfs/xfs_inode_fork.c:541:2: WARNING: Assigning signed result to
unsigned variable: new_size = XFS_BMAP_BROOT_SPACE_CALC(...)
As you see most of them are macros, of_get_child_count and btrfs_copy_from_user
return int but always non-negative.
Regards
Andrzej
>
> julia
>
>> unsigned_lesser_than_zero.cocci patch posted earlier has found
>> 40 problems [3][4], and about 80 false positives if I remember correctly.
>> Few patches were rejected, as developers likes code for testing variable range,
>> even if its result is always true/false [5][6], but most of kernel patches are
>> real bug fixes.
>>
>> Both patches tries to address similar issues, maybe it would be good to merge
>> them? Especially as their results overlap.
>> Additionally I thought about adding detecting range checks in
>> unsigned_lesser_than_zero.cocci, to decrease number of false positives.
>> Of course it could then miss real bugs. What do you think about it?
>>
>> [1]: http://permalink.gmane.org/gmane.linux.kernel/2046131
>> [2]: http://permalink.gmane.org/gmane.linux.kernel/2048070
>> [3]: http://permalink.gmane.org/gmane.comp.freedesktop.xorg.drivers.intel/70031
>> [4]: http://permalink.gmane.org/gmane.linux.power-management.general/66143
>> [5]: http://permalink.gmane.org/gmane.linux.kernel.mm/138902
>> [6]: http://libdivecomputer.org/pipermail/devel/2014-July/000329.html
>>
>> Regards
>> Andrzej
>>
>> ---
>> .../tests/assign_signed_to_unsigned.cocci | 45 ++++++++++++++++++++++
>> 1 file changed, 45 insertions(+)
>> create mode 100644 scripts/coccinelle/tests/assign_signed_to_unsigned.cocci
>>
>> diff --git a/scripts/coccinelle/tests/assign_signed_to_unsigned.cocci b/scripts/coccinelle/tests/assign_signed_to_unsigned.cocci
>> new file mode 100644
>> index 0000000..efa4e83
>> --- /dev/null
>> +++ b/scripts/coccinelle/tests/assign_signed_to_unsigned.cocci
>> @@ -0,0 +1,45 @@
>> +/// Assigning signed function result to unsigned variable can indicate error.
>> +/// To decrease number of false positives patch looks if after assignment
>> +/// there is also check for negative values of the result.
>> +///
>> +// Confidence: High
>> +// Copyright: (C) 2015 Andrzej Hajda, Samsung Electronics Co., Ltd. GPLv2.
>> +// URL: http://coccinelle.lip6.fr/
>> +// Options: --include-headers --all-includes
>> +
>> +virtual context
>> +virtual org
>> +virtual report
>> +
>> + at r@
>> +typedef bool, u8, u16, u32, u64, s8, s16, s32, s64;
>> +{char, short, int, long, long long, s8, s16, s32, s64} vs;
>> +{unsigned char, unsigned short, unsigned int, unsigned long, unsigned long long,
>> + size_t, bool, u8, u16, u32, u64} vu;
>> +position p;
>> +identifier f;
>> +statement S1, S2;
>> +expression e;
>> +@@
>> +
>> +*vu at p = f(...)@vs;
>> +... when != vu = e;
>> +if ( \( vu < 0 \| vu <= 0 \) ) S1 else S2
>> +
>> + at script:python depends on r && org@
>> +p << r.p;
>> +f << r.f;
>> +vu << r.vu;
>> +@@
>> +
>> +msg = "WARNING: Assigning signed result to unsigned variable: %s = %s(...)" % (vu, f)
>> +coccilib.org.print_todo(p[0], msg)
>> +
>> + at script:python depends on r && report@
>> +p << r.p;
>> +f << r.f;
>> +vu << r.vu;
>> +@@
>> +
>> +msg = "WARNING: Assigning signed result to unsigned variable: %s = %s(...)" % (vu, f)
>> +coccilib.report.print_report(p[0], msg)
>> --
>> 1.9.1
>>
>>
^ permalink raw reply [flat|nested] 89+ messages in thread* Re: [PATCH v2] coccinelle: assign signed result to unsigned variable
@ 2015-09-28 11:59 ` Andrzej Hajda
0 siblings, 0 replies; 89+ messages in thread
From: Andrzej Hajda @ 2015-09-28 11:59 UTC (permalink / raw)
To: Julia Lawall
Cc: Bartlomiej Zolnierkiewicz, Marek Szyprowski, Gilles Muller,
Michal Marek, Nicolas Palix, kernel-janitors, linux-kernel, cocci,
elfring
On 09/28/2015 01:32 PM, Julia Lawall wrote:
>
> On Mon, 28 Sep 2015, Andrzej Hajda wrote:
>
>> Assigning signed function result to unsigned variable can indicate error.
>> To decrease number of false positives patch looks if after assignment
>> there is also check for negative values of the result.
>>
>> Signed-off-by: Andrzej Hajda <a.hajda@samsung.com>
>> ---
>> Hi Julia,
>>
>> Thanks for the hint. Now it looks much better.
>> Summarizing this patch has found 20 problems and has 22 false positives [1][2].
> Do you have some examples of the false positives?
./drivers/acpi/acpica/nsarguments.c:130:1: WARNING: Assigning signed result to
unsigned variable: required_param_count = METHOD_GET_ARG_COUNT(...)
./drivers/char/agp/intel-gtt.c:361:3: WARNING: Assigning signed result to
unsigned variable: stolen_size = KB(...)
./drivers/char/agp/intel-gtt.c:364:3: WARNING: Assigning signed result to
unsigned variable: stolen_size = MB(...)
./drivers/char/agp/intel-gtt.c:367:3: WARNING: Assigning signed result to
unsigned variable: stolen_size = MB(...)
./drivers/char/agp/intel-gtt.c:382:3: WARNING: Assigning signed result to
unsigned variable: stolen_size = MB(...)
./drivers/char/agp/intel-gtt.c:385:3: WARNING: Assigning signed result to
unsigned variable: stolen_size = MB(...)
./drivers/char/agp/intel-gtt.c:388:3: WARNING: Assigning signed result to
unsigned variable: stolen_size = MB(...)
./drivers/char/agp/intel-gtt.c:391:3: WARNING: Assigning signed result to
unsigned variable: stolen_size = MB(...)
./drivers/char/agp/intel-gtt.c:394:3: WARNING: Assigning signed result to
unsigned variable: stolen_size = MB(...)
./drivers/char/agp/intel-gtt.c:397:3: WARNING: Assigning signed result to
unsigned variable: stolen_size = MB(...)
./drivers/char/agp/intel-gtt.c:400:3: WARNING: Assigning signed result to
unsigned variable: stolen_size = MB(...)
./drivers/char/agp/intel-gtt.c:403:3: WARNING: Assigning signed result to
unsigned variable: stolen_size = MB(...)
./drivers/char/agp/intel-gtt.c:406:3: WARNING: Assigning signed result to
unsigned variable: stolen_size = MB(...)
./drivers/char/agp/intel-gtt.c:409:3: WARNING: Assigning signed result to
unsigned variable: stolen_size = MB(...)
./drivers/char/agp/intel-gtt.c:412:3: WARNING: Assigning signed result to
unsigned variable: stolen_size = MB(...)
./drivers/char/agp/intel-gtt.c:415:3: WARNING: Assigning signed result to
unsigned variable: stolen_size = MB(...)
./drivers/char/agp/intel-gtt.c:418:3: WARNING: Assigning signed result to
unsigned variable: stolen_size = MB(...)
./drivers/input/touchscreen/cyttsp4_core.c:967:1: WARNING: Assigning signed
result to unsigned variable: num_cur_tch = GET_NUM_TOUCHES(...)
./drivers/pinctrl/freescale/pinctrl-imx.c:648:2: WARNING: Assigning signed
result to unsigned variable: nfuncs = of_get_child_count(...)
./fs/btrfs/file.c:1572:2: WARNING: Assigning signed result to unsigned variable:
copied = btrfs_copy_from_user(...)
./fs/xfs/libxfs/xfs_inode_fork.c:541:2: WARNING: Assigning signed result to
unsigned variable: new_size = XFS_BMAP_BROOT_SPACE_CALC(...)
As you see most of them are macros, of_get_child_count and btrfs_copy_from_user
return int but always non-negative.
Regards
Andrzej
>
> julia
>
>> unsigned_lesser_than_zero.cocci patch posted earlier has found
>> 40 problems [3][4], and about 80 false positives if I remember correctly.
>> Few patches were rejected, as developers likes code for testing variable range,
>> even if its result is always true/false [5][6], but most of kernel patches are
>> real bug fixes.
>>
>> Both patches tries to address similar issues, maybe it would be good to merge
>> them? Especially as their results overlap.
>> Additionally I thought about adding detecting range checks in
>> unsigned_lesser_than_zero.cocci, to decrease number of false positives.
>> Of course it could then miss real bugs. What do you think about it?
>>
>> [1]: http://permalink.gmane.org/gmane.linux.kernel/2046131
>> [2]: http://permalink.gmane.org/gmane.linux.kernel/2048070
>> [3]: http://permalink.gmane.org/gmane.comp.freedesktop.xorg.drivers.intel/70031
>> [4]: http://permalink.gmane.org/gmane.linux.power-management.general/66143
>> [5]: http://permalink.gmane.org/gmane.linux.kernel.mm/138902
>> [6]: http://libdivecomputer.org/pipermail/devel/2014-July/000329.html
>>
>> Regards
>> Andrzej
>>
>> ---
>> .../tests/assign_signed_to_unsigned.cocci | 45 ++++++++++++++++++++++
>> 1 file changed, 45 insertions(+)
>> create mode 100644 scripts/coccinelle/tests/assign_signed_to_unsigned.cocci
>>
>> diff --git a/scripts/coccinelle/tests/assign_signed_to_unsigned.cocci b/scripts/coccinelle/tests/assign_signed_to_unsigned.cocci
>> new file mode 100644
>> index 0000000..efa4e83
>> --- /dev/null
>> +++ b/scripts/coccinelle/tests/assign_signed_to_unsigned.cocci
>> @@ -0,0 +1,45 @@
>> +/// Assigning signed function result to unsigned variable can indicate error.
>> +/// To decrease number of false positives patch looks if after assignment
>> +/// there is also check for negative values of the result.
>> +///
>> +// Confidence: High
>> +// Copyright: (C) 2015 Andrzej Hajda, Samsung Electronics Co., Ltd. GPLv2.
>> +// URL: http://coccinelle.lip6.fr/
>> +// Options: --include-headers --all-includes
>> +
>> +virtual context
>> +virtual org
>> +virtual report
>> +
>> +@r@
>> +typedef bool, u8, u16, u32, u64, s8, s16, s32, s64;
>> +{char, short, int, long, long long, s8, s16, s32, s64} vs;
>> +{unsigned char, unsigned short, unsigned int, unsigned long, unsigned long long,
>> + size_t, bool, u8, u16, u32, u64} vu;
>> +position p;
>> +identifier f;
>> +statement S1, S2;
>> +expression e;
>> +@@
>> +
>> +*vu@p = f(...)@vs;
>> +... when != vu = e;
>> +if ( \( vu < 0 \| vu <= 0 \) ) S1 else S2
>> +
>> +@script:python depends on r && org@
>> +p << r.p;
>> +f << r.f;
>> +vu << r.vu;
>> +@@
>> +
>> +msg = "WARNING: Assigning signed result to unsigned variable: %s = %s(...)" % (vu, f)
>> +coccilib.org.print_todo(p[0], msg)
>> +
>> +@script:python depends on r && report@
>> +p << r.p;
>> +f << r.f;
>> +vu << r.vu;
>> +@@
>> +
>> +msg = "WARNING: Assigning signed result to unsigned variable: %s = %s(...)" % (vu, f)
>> +coccilib.report.print_report(p[0], msg)
>> --
>> 1.9.1
>>
>>
^ permalink raw reply [flat|nested] 89+ messages in thread* Re: [PATCH v2] coccinelle: assign signed result to unsigned variable
@ 2015-09-28 11:59 ` Andrzej Hajda
0 siblings, 0 replies; 89+ messages in thread
From: Andrzej Hajda @ 2015-09-28 11:59 UTC (permalink / raw)
To: cocci
On 09/28/2015 01:32 PM, Julia Lawall wrote:
>
> On Mon, 28 Sep 2015, Andrzej Hajda wrote:
>
>> Assigning signed function result to unsigned variable can indicate error.
>> To decrease number of false positives patch looks if after assignment
>> there is also check for negative values of the result.
>>
>> Signed-off-by: Andrzej Hajda <a.hajda@samsung.com>
>> ---
>> Hi Julia,
>>
>> Thanks for the hint. Now it looks much better.
>> Summarizing this patch has found 20 problems and has 22 false positives [1][2].
> Do you have some examples of the false positives?
./drivers/acpi/acpica/nsarguments.c:130:1: WARNING: Assigning signed result to
unsigned variable: required_param_count = METHOD_GET_ARG_COUNT(...)
./drivers/char/agp/intel-gtt.c:361:3: WARNING: Assigning signed result to
unsigned variable: stolen_size = KB(...)
./drivers/char/agp/intel-gtt.c:364:3: WARNING: Assigning signed result to
unsigned variable: stolen_size = MB(...)
./drivers/char/agp/intel-gtt.c:367:3: WARNING: Assigning signed result to
unsigned variable: stolen_size = MB(...)
./drivers/char/agp/intel-gtt.c:382:3: WARNING: Assigning signed result to
unsigned variable: stolen_size = MB(...)
./drivers/char/agp/intel-gtt.c:385:3: WARNING: Assigning signed result to
unsigned variable: stolen_size = MB(...)
./drivers/char/agp/intel-gtt.c:388:3: WARNING: Assigning signed result to
unsigned variable: stolen_size = MB(...)
./drivers/char/agp/intel-gtt.c:391:3: WARNING: Assigning signed result to
unsigned variable: stolen_size = MB(...)
./drivers/char/agp/intel-gtt.c:394:3: WARNING: Assigning signed result to
unsigned variable: stolen_size = MB(...)
./drivers/char/agp/intel-gtt.c:397:3: WARNING: Assigning signed result to
unsigned variable: stolen_size = MB(...)
./drivers/char/agp/intel-gtt.c:400:3: WARNING: Assigning signed result to
unsigned variable: stolen_size = MB(...)
./drivers/char/agp/intel-gtt.c:403:3: WARNING: Assigning signed result to
unsigned variable: stolen_size = MB(...)
./drivers/char/agp/intel-gtt.c:406:3: WARNING: Assigning signed result to
unsigned variable: stolen_size = MB(...)
./drivers/char/agp/intel-gtt.c:409:3: WARNING: Assigning signed result to
unsigned variable: stolen_size = MB(...)
./drivers/char/agp/intel-gtt.c:412:3: WARNING: Assigning signed result to
unsigned variable: stolen_size = MB(...)
./drivers/char/agp/intel-gtt.c:415:3: WARNING: Assigning signed result to
unsigned variable: stolen_size = MB(...)
./drivers/char/agp/intel-gtt.c:418:3: WARNING: Assigning signed result to
unsigned variable: stolen_size = MB(...)
./drivers/input/touchscreen/cyttsp4_core.c:967:1: WARNING: Assigning signed
result to unsigned variable: num_cur_tch = GET_NUM_TOUCHES(...)
./drivers/pinctrl/freescale/pinctrl-imx.c:648:2: WARNING: Assigning signed
result to unsigned variable: nfuncs = of_get_child_count(...)
./fs/btrfs/file.c:1572:2: WARNING: Assigning signed result to unsigned variable:
copied = btrfs_copy_from_user(...)
./fs/xfs/libxfs/xfs_inode_fork.c:541:2: WARNING: Assigning signed result to
unsigned variable: new_size = XFS_BMAP_BROOT_SPACE_CALC(...)
As you see most of them are macros, of_get_child_count and btrfs_copy_from_user
return int but always non-negative.
Regards
Andrzej
>
> julia
>
>> unsigned_lesser_than_zero.cocci patch posted earlier has found
>> 40 problems [3][4], and about 80 false positives if I remember correctly.
>> Few patches were rejected, as developers likes code for testing variable range,
>> even if its result is always true/false [5][6], but most of kernel patches are
>> real bug fixes.
>>
>> Both patches tries to address similar issues, maybe it would be good to merge
>> them? Especially as their results overlap.
>> Additionally I thought about adding detecting range checks in
>> unsigned_lesser_than_zero.cocci, to decrease number of false positives.
>> Of course it could then miss real bugs. What do you think about it?
>>
>> [1]: http://permalink.gmane.org/gmane.linux.kernel/2046131
>> [2]: http://permalink.gmane.org/gmane.linux.kernel/2048070
>> [3]: http://permalink.gmane.org/gmane.comp.freedesktop.xorg.drivers.intel/70031
>> [4]: http://permalink.gmane.org/gmane.linux.power-management.general/66143
>> [5]: http://permalink.gmane.org/gmane.linux.kernel.mm/138902
>> [6]: http://libdivecomputer.org/pipermail/devel/2014-July/000329.html
>>
>> Regards
>> Andrzej
>>
>> ---
>> .../tests/assign_signed_to_unsigned.cocci | 45 ++++++++++++++++++++++
>> 1 file changed, 45 insertions(+)
>> create mode 100644 scripts/coccinelle/tests/assign_signed_to_unsigned.cocci
>>
>> diff --git a/scripts/coccinelle/tests/assign_signed_to_unsigned.cocci b/scripts/coccinelle/tests/assign_signed_to_unsigned.cocci
>> new file mode 100644
>> index 0000000..efa4e83
>> --- /dev/null
>> +++ b/scripts/coccinelle/tests/assign_signed_to_unsigned.cocci
>> @@ -0,0 +1,45 @@
>> +/// Assigning signed function result to unsigned variable can indicate error.
>> +/// To decrease number of false positives patch looks if after assignment
>> +/// there is also check for negative values of the result.
>> +///
>> +// Confidence: High
>> +// Copyright: (C) 2015 Andrzej Hajda, Samsung Electronics Co., Ltd. GPLv2.
>> +// URL: http://coccinelle.lip6.fr/
>> +// Options: --include-headers --all-includes
>> +
>> +virtual context
>> +virtual org
>> +virtual report
>> +
>> +@r@
>> +typedef bool, u8, u16, u32, u64, s8, s16, s32, s64;
>> +{char, short, int, long, long long, s8, s16, s32, s64} vs;
>> +{unsigned char, unsigned short, unsigned int, unsigned long, unsigned long long,
>> + size_t, bool, u8, u16, u32, u64} vu;
>> +position p;
>> +identifier f;
>> +statement S1, S2;
>> +expression e;
>> +@@
>> +
>> +*vu@p = f(...)@vs;
>> +... when != vu = e;
>> +if ( \( vu < 0 \| vu <= 0 \) ) S1 else S2
>> +
>> +@script:python depends on r && org@
>> +p << r.p;
>> +f << r.f;
>> +vu << r.vu;
>> +@@
>> +
>> +msg = "WARNING: Assigning signed result to unsigned variable: %s = %s(...)" % (vu, f)
>> +coccilib.org.print_todo(p[0], msg)
>> +
>> +@script:python depends on r && report@
>> +p << r.p;
>> +f << r.f;
>> +vu << r.vu;
>> +@@
>> +
>> +msg = "WARNING: Assigning signed result to unsigned variable: %s = %s(...)" % (vu, f)
>> +coccilib.report.print_report(p[0], msg)
>> --
>> 1.9.1
>>
>>
^ permalink raw reply [flat|nested] 89+ messages in thread* [Cocci] [PATCH v2] coccinelle: assign signed result to unsigned variable
2015-09-28 11:59 ` Andrzej Hajda
(?)
@ 2015-09-30 21:51 ` Julia Lawall
-1 siblings, 0 replies; 89+ messages in thread
From: Julia Lawall @ 2015-09-30 21:51 UTC (permalink / raw)
To: cocci
On Mon, 28 Sep 2015, Andrzej Hajda wrote:
> On 09/28/2015 01:32 PM, Julia Lawall wrote:
> >
> > On Mon, 28 Sep 2015, Andrzej Hajda wrote:
> >
> >> Assigning signed function result to unsigned variable can indicate error.
> >> To decrease number of false positives patch looks if after assignment
> >> there is also check for negative values of the result.
> >>
> >> Signed-off-by: Andrzej Hajda <a.hajda@samsung.com>
> >> ---
> >> Hi Julia,
> >>
> >> Thanks for the hint. Now it looks much better.
> >> Summarizing this patch has found 20 problems and has 22 false positives [1][2].
> > Do you have some examples of the false positives?
> ./drivers/acpi/acpica/nsarguments.c:130:1: WARNING: Assigning signed result to
> unsigned variable: required_param_count = METHOD_GET_ARG_COUNT(...)
> ./drivers/char/agp/intel-gtt.c:361:3: WARNING: Assigning signed result to
> unsigned variable: stolen_size = KB(...)
> ./drivers/char/agp/intel-gtt.c:364:3: WARNING: Assigning signed result to
> unsigned variable: stolen_size = MB(...)
> ./drivers/char/agp/intel-gtt.c:367:3: WARNING: Assigning signed result to
> unsigned variable: stolen_size = MB(...)
> ./drivers/char/agp/intel-gtt.c:382:3: WARNING: Assigning signed result to
> unsigned variable: stolen_size = MB(...)
> ./drivers/char/agp/intel-gtt.c:385:3: WARNING: Assigning signed result to
> unsigned variable: stolen_size = MB(...)
> ./drivers/char/agp/intel-gtt.c:388:3: WARNING: Assigning signed result to
> unsigned variable: stolen_size = MB(...)
> ./drivers/char/agp/intel-gtt.c:391:3: WARNING: Assigning signed result to
> unsigned variable: stolen_size = MB(...)
> ./drivers/char/agp/intel-gtt.c:394:3: WARNING: Assigning signed result to
> unsigned variable: stolen_size = MB(...)
> ./drivers/char/agp/intel-gtt.c:397:3: WARNING: Assigning signed result to
> unsigned variable: stolen_size = MB(...)
> ./drivers/char/agp/intel-gtt.c:400:3: WARNING: Assigning signed result to
> unsigned variable: stolen_size = MB(...)
> ./drivers/char/agp/intel-gtt.c:403:3: WARNING: Assigning signed result to
> unsigned variable: stolen_size = MB(...)
> ./drivers/char/agp/intel-gtt.c:406:3: WARNING: Assigning signed result to
> unsigned variable: stolen_size = MB(...)
> ./drivers/char/agp/intel-gtt.c:409:3: WARNING: Assigning signed result to
> unsigned variable: stolen_size = MB(...)
> ./drivers/char/agp/intel-gtt.c:412:3: WARNING: Assigning signed result to
> unsigned variable: stolen_size = MB(...)
> ./drivers/char/agp/intel-gtt.c:415:3: WARNING: Assigning signed result to
> unsigned variable: stolen_size = MB(...)
> ./drivers/char/agp/intel-gtt.c:418:3: WARNING: Assigning signed result to
> unsigned variable: stolen_size = MB(...)
> ./drivers/input/touchscreen/cyttsp4_core.c:967:1: WARNING: Assigning signed
> result to unsigned variable: num_cur_tch = GET_NUM_TOUCHES(...)
> ./drivers/pinctrl/freescale/pinctrl-imx.c:648:2: WARNING: Assigning signed
> result to unsigned variable: nfuncs = of_get_child_count(...)
> ./fs/btrfs/file.c:1572:2: WARNING: Assigning signed result to unsigned variable:
> copied = btrfs_copy_from_user(...)
> ./fs/xfs/libxfs/xfs_inode_fork.c:541:2: WARNING: Assigning signed result to
> unsigned variable: new_size = XFS_BMAP_BROOT_SPACE_CALC(...)
>
> As you see most of them are macros, of_get_child_count and btrfs_copy_from_user
> return int but always non-negative.
OK, perhaps we could just live with them...
julia
^ permalink raw reply [flat|nested] 89+ messages in thread
* Re: [PATCH v2] coccinelle: assign signed result to unsigned variable
@ 2015-09-30 21:51 ` Julia Lawall
0 siblings, 0 replies; 89+ messages in thread
From: Julia Lawall @ 2015-09-30 21:51 UTC (permalink / raw)
To: Andrzej Hajda
Cc: Julia Lawall, Bartlomiej Zolnierkiewicz, Marek Szyprowski,
Gilles Muller, Michal Marek, Nicolas Palix, kernel-janitors,
linux-kernel, cocci, elfring
On Mon, 28 Sep 2015, Andrzej Hajda wrote:
> On 09/28/2015 01:32 PM, Julia Lawall wrote:
> >
> > On Mon, 28 Sep 2015, Andrzej Hajda wrote:
> >
> >> Assigning signed function result to unsigned variable can indicate error.
> >> To decrease number of false positives patch looks if after assignment
> >> there is also check for negative values of the result.
> >>
> >> Signed-off-by: Andrzej Hajda <a.hajda@samsung.com>
> >> ---
> >> Hi Julia,
> >>
> >> Thanks for the hint. Now it looks much better.
> >> Summarizing this patch has found 20 problems and has 22 false positives [1][2].
> > Do you have some examples of the false positives?
> ./drivers/acpi/acpica/nsarguments.c:130:1: WARNING: Assigning signed result to
> unsigned variable: required_param_count = METHOD_GET_ARG_COUNT(...)
> ./drivers/char/agp/intel-gtt.c:361:3: WARNING: Assigning signed result to
> unsigned variable: stolen_size = KB(...)
> ./drivers/char/agp/intel-gtt.c:364:3: WARNING: Assigning signed result to
> unsigned variable: stolen_size = MB(...)
> ./drivers/char/agp/intel-gtt.c:367:3: WARNING: Assigning signed result to
> unsigned variable: stolen_size = MB(...)
> ./drivers/char/agp/intel-gtt.c:382:3: WARNING: Assigning signed result to
> unsigned variable: stolen_size = MB(...)
> ./drivers/char/agp/intel-gtt.c:385:3: WARNING: Assigning signed result to
> unsigned variable: stolen_size = MB(...)
> ./drivers/char/agp/intel-gtt.c:388:3: WARNING: Assigning signed result to
> unsigned variable: stolen_size = MB(...)
> ./drivers/char/agp/intel-gtt.c:391:3: WARNING: Assigning signed result to
> unsigned variable: stolen_size = MB(...)
> ./drivers/char/agp/intel-gtt.c:394:3: WARNING: Assigning signed result to
> unsigned variable: stolen_size = MB(...)
> ./drivers/char/agp/intel-gtt.c:397:3: WARNING: Assigning signed result to
> unsigned variable: stolen_size = MB(...)
> ./drivers/char/agp/intel-gtt.c:400:3: WARNING: Assigning signed result to
> unsigned variable: stolen_size = MB(...)
> ./drivers/char/agp/intel-gtt.c:403:3: WARNING: Assigning signed result to
> unsigned variable: stolen_size = MB(...)
> ./drivers/char/agp/intel-gtt.c:406:3: WARNING: Assigning signed result to
> unsigned variable: stolen_size = MB(...)
> ./drivers/char/agp/intel-gtt.c:409:3: WARNING: Assigning signed result to
> unsigned variable: stolen_size = MB(...)
> ./drivers/char/agp/intel-gtt.c:412:3: WARNING: Assigning signed result to
> unsigned variable: stolen_size = MB(...)
> ./drivers/char/agp/intel-gtt.c:415:3: WARNING: Assigning signed result to
> unsigned variable: stolen_size = MB(...)
> ./drivers/char/agp/intel-gtt.c:418:3: WARNING: Assigning signed result to
> unsigned variable: stolen_size = MB(...)
> ./drivers/input/touchscreen/cyttsp4_core.c:967:1: WARNING: Assigning signed
> result to unsigned variable: num_cur_tch = GET_NUM_TOUCHES(...)
> ./drivers/pinctrl/freescale/pinctrl-imx.c:648:2: WARNING: Assigning signed
> result to unsigned variable: nfuncs = of_get_child_count(...)
> ./fs/btrfs/file.c:1572:2: WARNING: Assigning signed result to unsigned variable:
> copied = btrfs_copy_from_user(...)
> ./fs/xfs/libxfs/xfs_inode_fork.c:541:2: WARNING: Assigning signed result to
> unsigned variable: new_size = XFS_BMAP_BROOT_SPACE_CALC(...)
>
> As you see most of them are macros, of_get_child_count and btrfs_copy_from_user
> return int but always non-negative.
OK, perhaps we could just live with them...
julia
^ permalink raw reply [flat|nested] 89+ messages in thread
* Re: [PATCH v2] coccinelle: assign signed result to unsigned variable
@ 2015-09-30 21:51 ` Julia Lawall
0 siblings, 0 replies; 89+ messages in thread
From: Julia Lawall @ 2015-09-30 21:51 UTC (permalink / raw)
To: cocci
On Mon, 28 Sep 2015, Andrzej Hajda wrote:
> On 09/28/2015 01:32 PM, Julia Lawall wrote:
> >
> > On Mon, 28 Sep 2015, Andrzej Hajda wrote:
> >
> >> Assigning signed function result to unsigned variable can indicate error.
> >> To decrease number of false positives patch looks if after assignment
> >> there is also check for negative values of the result.
> >>
> >> Signed-off-by: Andrzej Hajda <a.hajda@samsung.com>
> >> ---
> >> Hi Julia,
> >>
> >> Thanks for the hint. Now it looks much better.
> >> Summarizing this patch has found 20 problems and has 22 false positives [1][2].
> > Do you have some examples of the false positives?
> ./drivers/acpi/acpica/nsarguments.c:130:1: WARNING: Assigning signed result to
> unsigned variable: required_param_count = METHOD_GET_ARG_COUNT(...)
> ./drivers/char/agp/intel-gtt.c:361:3: WARNING: Assigning signed result to
> unsigned variable: stolen_size = KB(...)
> ./drivers/char/agp/intel-gtt.c:364:3: WARNING: Assigning signed result to
> unsigned variable: stolen_size = MB(...)
> ./drivers/char/agp/intel-gtt.c:367:3: WARNING: Assigning signed result to
> unsigned variable: stolen_size = MB(...)
> ./drivers/char/agp/intel-gtt.c:382:3: WARNING: Assigning signed result to
> unsigned variable: stolen_size = MB(...)
> ./drivers/char/agp/intel-gtt.c:385:3: WARNING: Assigning signed result to
> unsigned variable: stolen_size = MB(...)
> ./drivers/char/agp/intel-gtt.c:388:3: WARNING: Assigning signed result to
> unsigned variable: stolen_size = MB(...)
> ./drivers/char/agp/intel-gtt.c:391:3: WARNING: Assigning signed result to
> unsigned variable: stolen_size = MB(...)
> ./drivers/char/agp/intel-gtt.c:394:3: WARNING: Assigning signed result to
> unsigned variable: stolen_size = MB(...)
> ./drivers/char/agp/intel-gtt.c:397:3: WARNING: Assigning signed result to
> unsigned variable: stolen_size = MB(...)
> ./drivers/char/agp/intel-gtt.c:400:3: WARNING: Assigning signed result to
> unsigned variable: stolen_size = MB(...)
> ./drivers/char/agp/intel-gtt.c:403:3: WARNING: Assigning signed result to
> unsigned variable: stolen_size = MB(...)
> ./drivers/char/agp/intel-gtt.c:406:3: WARNING: Assigning signed result to
> unsigned variable: stolen_size = MB(...)
> ./drivers/char/agp/intel-gtt.c:409:3: WARNING: Assigning signed result to
> unsigned variable: stolen_size = MB(...)
> ./drivers/char/agp/intel-gtt.c:412:3: WARNING: Assigning signed result to
> unsigned variable: stolen_size = MB(...)
> ./drivers/char/agp/intel-gtt.c:415:3: WARNING: Assigning signed result to
> unsigned variable: stolen_size = MB(...)
> ./drivers/char/agp/intel-gtt.c:418:3: WARNING: Assigning signed result to
> unsigned variable: stolen_size = MB(...)
> ./drivers/input/touchscreen/cyttsp4_core.c:967:1: WARNING: Assigning signed
> result to unsigned variable: num_cur_tch = GET_NUM_TOUCHES(...)
> ./drivers/pinctrl/freescale/pinctrl-imx.c:648:2: WARNING: Assigning signed
> result to unsigned variable: nfuncs = of_get_child_count(...)
> ./fs/btrfs/file.c:1572:2: WARNING: Assigning signed result to unsigned variable:
> copied = btrfs_copy_from_user(...)
> ./fs/xfs/libxfs/xfs_inode_fork.c:541:2: WARNING: Assigning signed result to
> unsigned variable: new_size = XFS_BMAP_BROOT_SPACE_CALC(...)
>
> As you see most of them are macros, of_get_child_count and btrfs_copy_from_user
> return int but always non-negative.
OK, perhaps we could just live with them...
julia
^ permalink raw reply [flat|nested] 89+ messages in thread
* [Cocci] [PATCH v2] coccinelle: assign signed result to unsigned variable
2015-09-28 10:54 ` Andrzej Hajda
(?)
@ 2015-09-28 12:07 ` SF Markus Elfring
-1 siblings, 0 replies; 89+ messages in thread
From: SF Markus Elfring @ 2015-09-28 12:07 UTC (permalink / raw)
To: cocci
> +// Options: --include-headers --all-includes
How do you think about the reuse of the parameter "--recursive-includes" here?
Will the list of checked function calls become more complete then?
Regards,
Markus
^ permalink raw reply [flat|nested] 89+ messages in thread
* Re: [PATCH v2] coccinelle: assign signed result to unsigned variable
@ 2015-09-28 12:07 ` SF Markus Elfring
0 siblings, 0 replies; 89+ messages in thread
From: SF Markus Elfring @ 2015-09-28 12:07 UTC (permalink / raw)
To: Andrzej Hajda
Cc: Bartlomiej Zolnierkiewicz, Gilles Muller, Marek Szyprowski,
Michal Marek, Nicolas Palix, kernel-janitors, linux-kernel, cocci
> +// Options: --include-headers --all-includes
How do you think about the reuse of the parameter "--recursive-includes" here?
Will the list of checked function calls become more complete then?
Regards,
Markus
^ permalink raw reply [flat|nested] 89+ messages in thread
* Re: [PATCH v2] coccinelle: assign signed result to unsigned variable
@ 2015-09-28 12:07 ` SF Markus Elfring
0 siblings, 0 replies; 89+ messages in thread
From: SF Markus Elfring @ 2015-09-28 12:07 UTC (permalink / raw)
To: cocci
> +// Options: --include-headers --all-includes
How do you think about the reuse of the parameter "--recursive-includes" here?
Will the list of checked function calls become more complete then?
Regards,
Markus
^ permalink raw reply [flat|nested] 89+ messages in thread
* [Cocci] [PATCH v2] coccinelle: assign signed result to unsigned variable
2015-09-28 12:07 ` SF Markus Elfring
(?)
@ 2015-09-28 12:12 ` Andrzej Hajda
-1 siblings, 0 replies; 89+ messages in thread
From: Andrzej Hajda @ 2015-09-28 12:12 UTC (permalink / raw)
To: cocci
On 09/28/2015 02:07 PM, SF Markus Elfring wrote:
>> +// Options: --include-headers --all-includes
>
> How do you think about the reuse of the parameter "--recursive-includes" here?
Last time I have tried it, kernel source check took more than 10 hours, so I
gave up.
Regards
Andrzej
>
> Will the list of checked function calls become more complete then?
>
> Regards,
> Markus
> --
> To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
> the body of a message to majordomo at vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 89+ messages in thread
* Re: [PATCH v2] coccinelle: assign signed result to unsigned variable
@ 2015-09-28 12:12 ` Andrzej Hajda
0 siblings, 0 replies; 89+ messages in thread
From: Andrzej Hajda @ 2015-09-28 12:12 UTC (permalink / raw)
To: SF Markus Elfring
Cc: Bartlomiej Zolnierkiewicz, Gilles Muller, Marek Szyprowski,
Michal Marek, Nicolas Palix, kernel-janitors, linux-kernel, cocci
On 09/28/2015 02:07 PM, SF Markus Elfring wrote:
>> +// Options: --include-headers --all-includes
>
> How do you think about the reuse of the parameter "--recursive-includes" here?
Last time I have tried it, kernel source check took more than 10 hours, so I
gave up.
Regards
Andrzej
>
> Will the list of checked function calls become more complete then?
>
> Regards,
> Markus
> --
> To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 89+ messages in thread
* Re: [PATCH v2] coccinelle: assign signed result to unsigned variable
@ 2015-09-28 12:12 ` Andrzej Hajda
0 siblings, 0 replies; 89+ messages in thread
From: Andrzej Hajda @ 2015-09-28 12:12 UTC (permalink / raw)
To: cocci
On 09/28/2015 02:07 PM, SF Markus Elfring wrote:
>> +// Options: --include-headers --all-includes
>
> How do you think about the reuse of the parameter "--recursive-includes" here?
Last time I have tried it, kernel source check took more than 10 hours, so I
gave up.
Regards
Andrzej
>
> Will the list of checked function calls become more complete then?
>
> Regards,
> Markus
> --
> To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 89+ messages in thread
* [Cocci] [PATCH v2] coccinelle: assign signed result to unsigned variable
2015-09-28 12:12 ` Andrzej Hajda
(?)
@ 2015-09-28 12:20 ` SF Markus Elfring
-1 siblings, 0 replies; 89+ messages in thread
From: SF Markus Elfring @ 2015-09-28 12:20 UTC (permalink / raw)
To: cocci
>> How do you think about the reuse of the parameter "--recursive-includes" here?
>
> Last time I have tried it, kernel source check took more than 10 hours,
> so I gave up.
This is interesting background information.
There are opportunities for more fine-tuning of such a source code analysis,
aren't there?
Regards,
Markus
^ permalink raw reply [flat|nested] 89+ messages in thread
* Re: [PATCH v2] coccinelle: assign signed result to unsigned variable
@ 2015-09-28 12:20 ` SF Markus Elfring
0 siblings, 0 replies; 89+ messages in thread
From: SF Markus Elfring @ 2015-09-28 12:20 UTC (permalink / raw)
To: Andrzej Hajda
Cc: Bartlomiej Zolnierkiewicz, Gilles Muller, Marek Szyprowski,
Michal Marek, Nicolas Palix, kernel-janitors, linux-kernel, cocci
>> How do you think about the reuse of the parameter "--recursive-includes" here?
>
> Last time I have tried it, kernel source check took more than 10 hours,
> so I gave up.
This is interesting background information.
There are opportunities for more fine-tuning of such a source code analysis,
aren't there?
Regards,
Markus
^ permalink raw reply [flat|nested] 89+ messages in thread
* Re: [PATCH v2] coccinelle: assign signed result to unsigned variable
@ 2015-09-28 12:20 ` SF Markus Elfring
0 siblings, 0 replies; 89+ messages in thread
From: SF Markus Elfring @ 2015-09-28 12:20 UTC (permalink / raw)
To: cocci
>> How do you think about the reuse of the parameter "--recursive-includes" here?
>
> Last time I have tried it, kernel source check took more than 10 hours,
> so I gave up.
This is interesting background information.
There are opportunities for more fine-tuning of such a source code analysis,
aren't there?
Regards,
Markus
^ permalink raw reply [flat|nested] 89+ messages in thread
* [Cocci] [PATCH v2] coccinelle: assign signed result to unsigned variable
2015-09-28 12:20 ` SF Markus Elfring
(?)
@ 2015-09-28 12:42 ` Julia Lawall
-1 siblings, 0 replies; 89+ messages in thread
From: Julia Lawall @ 2015-09-28 12:42 UTC (permalink / raw)
To: cocci
On Mon, 28 Sep 2015, SF Markus Elfring wrote:
> >> How do you think about the reuse of the parameter "--recursive-includes" here?
> >
> > Last time I have tried it, kernel source check took more than 10 hours,
> > so I gave up.
>
> This is interesting background information.
>
> There are opportunities for more fine-tuning of such a source code analysis,
> aren't there?
I guess parallelism would be helpful? You could try the following
options:
-j n --chunksize 10 --recursive-includes --include-headers-for-types
where n is the number of cores that you want to use. Parsed header files
will be cached within chunks. I don't really know what is the best
chunksize.
julia
>
> Regards,
> Markus
> _______________________________________________
> Cocci mailing list
> Cocci at systeme.lip6.fr
> https://systeme.lip6.fr/mailman/listinfo/cocci
>
^ permalink raw reply [flat|nested] 89+ messages in thread
* Re: [Cocci] [PATCH v2] coccinelle: assign signed result to unsigned variable
@ 2015-09-28 12:42 ` Julia Lawall
0 siblings, 0 replies; 89+ messages in thread
From: Julia Lawall @ 2015-09-28 12:42 UTC (permalink / raw)
To: SF Markus Elfring
Cc: Andrzej Hajda, Bartlomiej Zolnierkiewicz, kernel-janitors,
linux-kernel, Michal Marek, cocci, Marek Szyprowski
On Mon, 28 Sep 2015, SF Markus Elfring wrote:
> >> How do you think about the reuse of the parameter "--recursive-includes" here?
> >
> > Last time I have tried it, kernel source check took more than 10 hours,
> > so I gave up.
>
> This is interesting background information.
>
> There are opportunities for more fine-tuning of such a source code analysis,
> aren't there?
I guess parallelism would be helpful? You could try the following
options:
-j n --chunksize 10 --recursive-includes --include-headers-for-types
where n is the number of cores that you want to use. Parsed header files
will be cached within chunks. I don't really know what is the best
chunksize.
julia
>
> Regards,
> Markus
> _______________________________________________
> Cocci mailing list
> Cocci@systeme.lip6.fr
> https://systeme.lip6.fr/mailman/listinfo/cocci
>
^ permalink raw reply [flat|nested] 89+ messages in thread
* Re: [Cocci] [PATCH v2] coccinelle: assign signed result to unsigned variable
@ 2015-09-28 12:42 ` Julia Lawall
0 siblings, 0 replies; 89+ messages in thread
From: Julia Lawall @ 2015-09-28 12:42 UTC (permalink / raw)
To: cocci
On Mon, 28 Sep 2015, SF Markus Elfring wrote:
> >> How do you think about the reuse of the parameter "--recursive-includes" here?
> >
> > Last time I have tried it, kernel source check took more than 10 hours,
> > so I gave up.
>
> This is interesting background information.
>
> There are opportunities for more fine-tuning of such a source code analysis,
> aren't there?
I guess parallelism would be helpful? You could try the following
options:
-j n --chunksize 10 --recursive-includes --include-headers-for-types
where n is the number of cores that you want to use. Parsed header files
will be cached within chunks. I don't really know what is the best
chunksize.
julia
>
> Regards,
> Markus
> _______________________________________________
> Cocci mailing list
> Cocci@systeme.lip6.fr
> https://systeme.lip6.fr/mailman/listinfo/cocci
>
^ permalink raw reply [flat|nested] 89+ messages in thread
* [Cocci] [PATCH v2] coccinelle: assign signed result to unsigned variable
2015-09-28 12:42 ` Julia Lawall
(?)
@ 2015-09-28 12:55 ` SF Markus Elfring
-1 siblings, 0 replies; 89+ messages in thread
From: SF Markus Elfring @ 2015-09-28 12:55 UTC (permalink / raw)
To: cocci
> I guess parallelism would be helpful?
> You could try the following options:
>
> -j n --chunksize 10 --recursive-includes --include-headers-for-types
>
> where n is the number of cores that you want to use.
Has the make target "coccicheck" direct support for such special parameters?
> Parsed header files will be cached within chunks.
Can the Coccinelle software work together with a kind of "precompiled
header database"?
Regards,
Markus
^ permalink raw reply [flat|nested] 89+ messages in thread
* Re: [Cocci] [PATCH v2] coccinelle: assign signed result to unsigned variable
@ 2015-09-28 12:55 ` SF Markus Elfring
0 siblings, 0 replies; 89+ messages in thread
From: SF Markus Elfring @ 2015-09-28 12:55 UTC (permalink / raw)
To: Julia Lawall
Cc: Andrzej Hajda, Bartlomiej Zolnierkiewicz, Marek Szyprowski,
Michal Marek, cocci, kernel-janitors, LKML
> I guess parallelism would be helpful?
> You could try the following options:
>
> -j n --chunksize 10 --recursive-includes --include-headers-for-types
>
> where n is the number of cores that you want to use.
Has the make target "coccicheck" direct support for such special parameters?
> Parsed header files will be cached within chunks.
Can the Coccinelle software work together with a kind of "precompiled
header database"?
Regards,
Markus
^ permalink raw reply [flat|nested] 89+ messages in thread
* Re: [Cocci] [PATCH v2] coccinelle: assign signed result to unsigned variable
@ 2015-09-28 12:55 ` SF Markus Elfring
0 siblings, 0 replies; 89+ messages in thread
From: SF Markus Elfring @ 2015-09-28 12:55 UTC (permalink / raw)
To: cocci
> I guess parallelism would be helpful?
> You could try the following options:
>
> -j n --chunksize 10 --recursive-includes --include-headers-for-types
>
> where n is the number of cores that you want to use.
Has the make target "coccicheck" direct support for such special parameters?
> Parsed header files will be cached within chunks.
Can the Coccinelle software work together with a kind of "precompiled
header database"?
Regards,
Markus
^ permalink raw reply [flat|nested] 89+ messages in thread
* [Cocci] [PATCH v2] coccinelle: assign signed result to unsigned variable
2015-09-28 12:55 ` SF Markus Elfring
(?)
@ 2015-09-28 13:13 ` Julia Lawall
-1 siblings, 0 replies; 89+ messages in thread
From: Julia Lawall @ 2015-09-28 13:13 UTC (permalink / raw)
To: cocci
On Mon, 28 Sep 2015, SF Markus Elfring wrote:
> > I guess parallelism would be helpful?
> > You could try the following options:
> >
> > -j n --chunksize 10 --recursive-includes --include-headers-for-types
> >
> > where n is the number of cores that you want to use.
>
> Has the make target "coccicheck" direct support for such special parameters?
>
>
> > Parsed header files will be cached within chunks.
>
> Can the Coccinelle software work together with a kind of "precompiled
> header database"?
There is an option --use-cache, which caches the compiled code on the
disk. But I have not found the effects to be very satisfactory. It is
still necessary to read in the serialized code.
julia
^ permalink raw reply [flat|nested] 89+ messages in thread
* Re: [Cocci] [PATCH v2] coccinelle: assign signed result to unsigned variable
@ 2015-09-28 13:13 ` Julia Lawall
0 siblings, 0 replies; 89+ messages in thread
From: Julia Lawall @ 2015-09-28 13:13 UTC (permalink / raw)
To: SF Markus Elfring
Cc: Julia Lawall, Andrzej Hajda, Bartlomiej Zolnierkiewicz,
Marek Szyprowski, Michal Marek, cocci, kernel-janitors, LKML
On Mon, 28 Sep 2015, SF Markus Elfring wrote:
> > I guess parallelism would be helpful?
> > You could try the following options:
> >
> > -j n --chunksize 10 --recursive-includes --include-headers-for-types
> >
> > where n is the number of cores that you want to use.
>
> Has the make target "coccicheck" direct support for such special parameters?
>
>
> > Parsed header files will be cached within chunks.
>
> Can the Coccinelle software work together with a kind of "precompiled
> header database"?
There is an option --use-cache, which caches the compiled code on the
disk. But I have not found the effects to be very satisfactory. It is
still necessary to read in the serialized code.
julia
^ permalink raw reply [flat|nested] 89+ messages in thread
* Re: [Cocci] [PATCH v2] coccinelle: assign signed result to unsigned variable
@ 2015-09-28 13:13 ` Julia Lawall
0 siblings, 0 replies; 89+ messages in thread
From: Julia Lawall @ 2015-09-28 13:13 UTC (permalink / raw)
To: cocci
On Mon, 28 Sep 2015, SF Markus Elfring wrote:
> > I guess parallelism would be helpful?
> > You could try the following options:
> >
> > -j n --chunksize 10 --recursive-includes --include-headers-for-types
> >
> > where n is the number of cores that you want to use.
>
> Has the make target "coccicheck" direct support for such special parameters?
>
>
> > Parsed header files will be cached within chunks.
>
> Can the Coccinelle software work together with a kind of "precompiled
> header database"?
There is an option --use-cache, which caches the compiled code on the
disk. But I have not found the effects to be very satisfactory. It is
still necessary to read in the serialized code.
julia
^ permalink raw reply [flat|nested] 89+ messages in thread
* [Cocci] [PATCH v2] coccinelle: assign signed result to unsigned variable
2015-09-28 13:13 ` Julia Lawall
(?)
@ 2015-09-28 13:53 ` SF Markus Elfring
-1 siblings, 0 replies; 89+ messages in thread
From: SF Markus Elfring @ 2015-09-28 13:53 UTC (permalink / raw)
To: cocci
>> Can the Coccinelle software work together with a kind of "precompiled
>> header database"?
>
> There is an option --use-cache, which caches the compiled code
> on the disk. But I have not found the effects to be very satisfactory.
I am curious if this situation will be improved by further software evolution.
Regards,
Markus
^ permalink raw reply [flat|nested] 89+ messages in thread
* Re: [Cocci] [PATCH v2] coccinelle: assign signed result to unsigned variable
@ 2015-09-28 13:53 ` SF Markus Elfring
0 siblings, 0 replies; 89+ messages in thread
From: SF Markus Elfring @ 2015-09-28 13:53 UTC (permalink / raw)
To: Julia Lawall
Cc: Andrzej Hajda, Bartlomiej Zolnierkiewicz, Marek Szyprowski,
Michal Marek, cocci, kernel-janitors, LKML
>> Can the Coccinelle software work together with a kind of "precompiled
>> header database"?
>
> There is an option --use-cache, which caches the compiled code
> on the disk. But I have not found the effects to be very satisfactory.
I am curious if this situation will be improved by further software evolution.
Regards,
Markus
^ permalink raw reply [flat|nested] 89+ messages in thread
* Re: [Cocci] [PATCH v2] coccinelle: assign signed result to unsigned variable
@ 2015-09-28 13:53 ` SF Markus Elfring
0 siblings, 0 replies; 89+ messages in thread
From: SF Markus Elfring @ 2015-09-28 13:53 UTC (permalink / raw)
To: cocci
>> Can the Coccinelle software work together with a kind of "precompiled
>> header database"?
>
> There is an option --use-cache, which caches the compiled code
> on the disk. But I have not found the effects to be very satisfactory.
I am curious if this situation will be improved by further software evolution.
Regards,
Markus
^ permalink raw reply [flat|nested] 89+ messages in thread
* [Cocci] [PATCH v2] coccinelle: assign signed result to unsigned variable
2015-09-28 13:53 ` SF Markus Elfring
(?)
@ 2015-09-28 15:07 ` Julia Lawall
-1 siblings, 0 replies; 89+ messages in thread
From: Julia Lawall @ 2015-09-28 15:07 UTC (permalink / raw)
To: cocci
On Mon, 28 Sep 2015, SF Markus Elfring wrote:
> >> Can the Coccinelle software work together with a kind of "precompiled
> >> header database"?
> >
> > There is an option --use-cache, which caches the compiled code
> > on the disk. But I have not found the effects to be very satisfactory.
>
> I am curious if this situation will be improved by further software evolution.
There are no plans in that direction.
julia
^ permalink raw reply [flat|nested] 89+ messages in thread
* Re: [Cocci] [PATCH v2] coccinelle: assign signed result to unsigned variable
@ 2015-09-28 15:07 ` Julia Lawall
0 siblings, 0 replies; 89+ messages in thread
From: Julia Lawall @ 2015-09-28 15:07 UTC (permalink / raw)
To: SF Markus Elfring
Cc: Julia Lawall, Andrzej Hajda, Bartlomiej Zolnierkiewicz,
Marek Szyprowski, Michal Marek, cocci, kernel-janitors, LKML
On Mon, 28 Sep 2015, SF Markus Elfring wrote:
> >> Can the Coccinelle software work together with a kind of "precompiled
> >> header database"?
> >
> > There is an option --use-cache, which caches the compiled code
> > on the disk. But I have not found the effects to be very satisfactory.
>
> I am curious if this situation will be improved by further software evolution.
There are no plans in that direction.
julia
^ permalink raw reply [flat|nested] 89+ messages in thread
* Re: [Cocci] [PATCH v2] coccinelle: assign signed result to unsigned variable
@ 2015-09-28 15:07 ` Julia Lawall
0 siblings, 0 replies; 89+ messages in thread
From: Julia Lawall @ 2015-09-28 15:07 UTC (permalink / raw)
To: cocci
On Mon, 28 Sep 2015, SF Markus Elfring wrote:
> >> Can the Coccinelle software work together with a kind of "precompiled
> >> header database"?
> >
> > There is an option --use-cache, which caches the compiled code
> > on the disk. But I have not found the effects to be very satisfactory.
>
> I am curious if this situation will be improved by further software evolution.
There are no plans in that direction.
julia
^ permalink raw reply [flat|nested] 89+ messages in thread
* [Cocci] [PATCH v2] coccinelle: assign signed result to unsigned variable
2015-09-28 10:54 ` Andrzej Hajda
(?)
@ 2015-10-03 7:09 ` Julia Lawall
-1 siblings, 0 replies; 89+ messages in thread
From: Julia Lawall @ 2015-10-03 7:09 UTC (permalink / raw)
To: cocci
Some comments:
If you get 20 good results and 22 false positives, I'm not sure whether
high confidence is justified. That seemes more like moderate confidence.
On the other hand, I think it is possible to get rid of the false
positives. The false positives are coming from the fact that you have:
if ( \( vu < 0 \| vu <= 0 \) ) S1 else S2
This can be flipped around to
if ( ! \( vu < 0 \| vu <= 0 \) ) S2 else S1
and then when we propagate the ! into the disjunction, we get v >= 0 for
the first condition and v > 0 for the second condition. v >= 0 is always
true, so it could be reasonable to highlight it, but v > 0 is a perfectly
reasonable test for an unsigned value, and is where you are getting the
false positives from. If you want to get rid of both v >= 0 and v < 0
then you can just put disable neg_if in the initial @@, just after r, ie
@r disable neg_if@
On the other hand, if you want to keep the warning on v >= 0 but drop the
warning on v > 0, then you will have to split the rules and put the
disable neg_if on the one for v <= 0.
I think it would also be reasonable to merge the proposed semantic
patches. I guess this one gives most of the results anyway?
With recursive_includes, I got 70 results,@least 20 of which should be
false positives due to the MB case.
julia
^ permalink raw reply [flat|nested] 89+ messages in thread
* Re: [PATCH v2] coccinelle: assign signed result to unsigned variable
@ 2015-10-03 7:09 ` Julia Lawall
0 siblings, 0 replies; 89+ messages in thread
From: Julia Lawall @ 2015-10-03 7:09 UTC (permalink / raw)
To: Andrzej Hajda
Cc: julia.lawall, Bartlomiej Zolnierkiewicz, Marek Szyprowski,
Gilles Muller, Michal Marek, Nicolas Palix, kernel-janitors,
linux-kernel, cocci, elfring
Some comments:
If you get 20 good results and 22 false positives, I'm not sure whether
high confidence is justified. That seemes more like moderate confidence.
On the other hand, I think it is possible to get rid of the false
positives. The false positives are coming from the fact that you have:
if ( \( vu < 0 \| vu <= 0 \) ) S1 else S2
This can be flipped around to
if ( ! \( vu < 0 \| vu <= 0 \) ) S2 else S1
and then when we propagate the ! into the disjunction, we get v >= 0 for
the first condition and v > 0 for the second condition. v >= 0 is always
true, so it could be reasonable to highlight it, but v > 0 is a perfectly
reasonable test for an unsigned value, and is where you are getting the
false positives from. If you want to get rid of both v >= 0 and v < 0
then you can just put disable neg_if in the initial @@, just after r, ie
@r disable neg_if@
On the other hand, if you want to keep the warning on v >= 0 but drop the
warning on v > 0, then you will have to split the rules and put the
disable neg_if on the one for v <= 0.
I think it would also be reasonable to merge the proposed semantic
patches. I guess this one gives most of the results anyway?
With recursive_includes, I got 70 results, at least 20 of which should be
false positives due to the MB case.
julia
^ permalink raw reply [flat|nested] 89+ messages in thread
* Re: [PATCH v2] coccinelle: assign signed result to unsigned variable
@ 2015-10-03 7:09 ` Julia Lawall
0 siblings, 0 replies; 89+ messages in thread
From: Julia Lawall @ 2015-10-03 7:09 UTC (permalink / raw)
To: cocci
Some comments:
If you get 20 good results and 22 false positives, I'm not sure whether
high confidence is justified. That seemes more like moderate confidence.
On the other hand, I think it is possible to get rid of the false
positives. The false positives are coming from the fact that you have:
if ( \( vu < 0 \| vu <= 0 \) ) S1 else S2
This can be flipped around to
if ( ! \( vu < 0 \| vu <= 0 \) ) S2 else S1
and then when we propagate the ! into the disjunction, we get v >= 0 for
the first condition and v > 0 for the second condition. v >= 0 is always
true, so it could be reasonable to highlight it, but v > 0 is a perfectly
reasonable test for an unsigned value, and is where you are getting the
false positives from. If you want to get rid of both v >= 0 and v < 0
then you can just put disable neg_if in the initial @@, just after r, ie
@r disable neg_if@
On the other hand, if you want to keep the warning on v >= 0 but drop the
warning on v > 0, then you will have to split the rules and put the
disable neg_if on the one for v <= 0.
I think it would also be reasonable to merge the proposed semantic
patches. I guess this one gives most of the results anyway?
With recursive_includes, I got 70 results, at least 20 of which should be
false positives due to the MB case.
julia
^ permalink raw reply [flat|nested] 89+ messages in thread