Re: [PATCH v3] coccinelle: tests: unsigned value cannot be lesser than zero
> In the example above spatch finds ull, ulli, but not ul and uli. > If you add int to unsigned long long, it won't find anything. I suggest to take another look at the use of type modifiers in the semantic patch language. It seems that it matters occasionally to specify them explicitly. How do you think about to reuse a SmPL script like the following? @find_unsigned@ typedef _Bool, bool, u8, u16, u32, u64; { unsigned, unsigned char, unsigned int, unsigned short, unsigned short int, unsigned long, unsigned long int, unsigned long long, unsigned long long int, size_t, _Bool, bool, u8, u16, u32, u64 } var; @@ *var Regards, Markus -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH v3] coccinelle: tests: unsigned value cannot be lesser than zero
On 09/22/2015 05:27 PM, SF Markus Elfring wrote: >> If you mean adding int to 'unsigned long [long]' types, it does not work. >> For some reason it works only without adding int after long. > Do you get any error message for this SmPL approach? > With which source files do you try the extended SmPL script out? > > Regards, > Markus > No, spatch just does not find everything it should. Sample below: --- test.cocci virtual context @r depends on context@ {unsigned char, unsigned short int, unsigned int, unsigned long int, unsigned long long, size_t} v; @@ *v --- test.c void f() { unsigned long ul; unsigned long int uli; unsigned long long ull; unsigned long long int ulli; ul; uli; ull; ulli; } --- In the example above spatch finds ull, ulli, but not ul and uli. If you add int to unsigned long long, it won't find anything. Regards Andrzej -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH v3] coccinelle: tests: unsigned value cannot be lesser than zero
> In the example above spatch finds ull, ulli, but not ul and uli. > If you add int to unsigned long long, it won't find anything. I suggest to take another look at the use of type modifiers in the semantic patch language. It seems that it matters occasionally to specify them explicitly. How do you think about to reuse a SmPL script like the following? @find_unsigned@ typedef _Bool, bool, u8, u16, u32, u64; { unsigned, unsigned char, unsigned int, unsigned short, unsigned short int, unsigned long, unsigned long int, unsigned long long, unsigned long long int, size_t, _Bool, bool, u8, u16, u32, u64 } var; @@ *var Regards, Markus -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH v3] coccinelle: tests: unsigned value cannot be lesser than zero
On 09/22/2015 05:27 PM, SF Markus Elfring wrote: >> If you mean adding int to 'unsigned long [long]' types, it does not work. >> For some reason it works only without adding int after long. > Do you get any error message for this SmPL approach? > With which source files do you try the extended SmPL script out? > > Regards, > Markus > No, spatch just does not find everything it should. Sample below: --- test.cocci virtual context @r depends on context@ {unsigned char, unsigned short int, unsigned int, unsigned long int, unsigned long long, size_t} v; @@ *v --- test.c void f() { unsigned long ul; unsigned long int uli; unsigned long long ull; unsigned long long int ulli; ul; uli; ull; ulli; } --- In the example above spatch finds ull, ulli, but not ul and uli. If you add int to unsigned long long, it won't find anything. Regards Andrzej -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH v3] coccinelle: tests: unsigned value cannot be lesser than zero
> If you mean adding int to 'unsigned long [long]' types, it does not work. > For some reason it works only without adding int after long. Do you get any error message for this SmPL approach? With which source files do you try the extended SmPL script out? Regards, Markus -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH v3] coccinelle: tests: unsigned value cannot be lesser than zero
> If you mean adding int to 'unsigned long [long]' types, it does not work. > For some reason it works only without adding int after long. Do you get any error message for this SmPL approach? With which source files do you try the extended SmPL script out? Regards, Markus -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH v3] coccinelle: tests: unsigned value cannot be lesser than zero
>> * Reuse of "long int"? > If you mean adding int to 'unsigned long [long]' types, it does not work. I am surprised. > For some reason it works only without adding int after long. The Coccinelle software should support the term "generic_ctype" from the SmPL grammar so far, shouldn't it? http://coccinelle.lip6.fr/docs/main_grammar005.html#ctype >> * Splitting of the suggested SmPL rule so that each source code check >> will be connected with appropriate warning messages. > Personally I prefer one message as it is more compact It might look convenient to combine a few source code checks. > and fits quite well in both cases, I got an other impression. > but I have no strong fillings with separate message for each case. * v@p < 0 Find places where this condition will always be false. *v@p >= 0 Find places where this condition will always be true. Will it help to distinguish these special cases also in your SmPL script strictly? Regards, Markus -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH v3] coccinelle: tests: unsigned value cannot be lesser than zero
On 09/21/2015 03:02 PM, SF Markus Elfring wrote: >> v3: added bool type > I would appreciate a bit more feedback for my concerns around your > evolving approach. Ups, I have missed your email. > * Reuse of "long int"? If you mean adding int to 'unsigned long [long]' types, it does not work. For some reason it works only without adding int after long. > * Splitting of the suggested SmPL rule so that each source code check > will be connected with appropriate warning messages. Personally I prefer one message as it is more compact and fits quite well in both cases, but I have no strong fillings with separate message for each case. > > Will any more fine-tuning be useful? Could you elaborate it. Regards Andrzej > > Regards, > Markus > -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH v3] coccinelle: tests: unsigned value cannot be lesser than zero
> v3: added bool type I would appreciate a bit more feedback for my concerns around your evolving approach. * Reuse of "long int"? * Splitting of the suggested SmPL rule so that each source code check will be connected with appropriate warning messages. Will any more fine-tuning be useful? Regards, Markus -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[PATCH v3] coccinelle: tests: unsigned value cannot be lesser than zero
Code comparing unsigned variables with zero using operators < or >= does not make sense. It is always false or true, respectively. However, its presence often indicates bugs in the code. gcc can detect it also using -Wtype-limits switch, but it warns also in correct cases, making too much noise. Signed-off-by: Andrzej Hajda Acked-by: Julia Lawall --- v3: added bool type v2: added --all-includes option --- .../tests/unsigned_lesser_than_zero.cocci | 37 ++ 1 file changed, 37 insertions(+) create mode 100644 scripts/coccinelle/tests/unsigned_lesser_than_zero.cocci diff --git a/scripts/coccinelle/tests/unsigned_lesser_than_zero.cocci b/scripts/coccinelle/tests/unsigned_lesser_than_zero.cocci new file mode 100644 index 000..70e71c8 --- /dev/null +++ b/scripts/coccinelle/tests/unsigned_lesser_than_zero.cocci @@ -0,0 +1,37 @@ +/// Unsigned variables cannot be lesser than zero. Presence of such checks +/// can indicate incorrect variable type or just unnecessary code. +/// +// 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 depends on context || org || report@ +position p; +typedef bool, u8, u16, u32, u64; +{unsigned char, unsigned short int, unsigned int, unsigned long, unsigned long long, size_t, bool, u8, u16, u32, u64} v; +@@ + +( +*v@p < 0 +| +*v@p >= 0 +) + +@script:python depends on org@ +p << r.p; +@@ + +msg = "WARNING: Unsigned value cannot be lesser than zero" +coccilib.org.print_todo(p[0], msg) + +@script:python depends on report@ +p << r.p; +@@ + +msg = "WARNING: Unsigned value cannot be lesser than zero" +coccilib.report.print_report(p[0], msg) -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH v3] coccinelle: tests: unsigned value cannot be lesser than zero
On 09/21/2015 03:02 PM, SF Markus Elfring wrote: >> v3: added bool type > I would appreciate a bit more feedback for my concerns around your > evolving approach. Ups, I have missed your email. > * Reuse of "long int"? If you mean adding int to 'unsigned long [long]' types, it does not work. For some reason it works only without adding int after long. > * Splitting of the suggested SmPL rule so that each source code check > will be connected with appropriate warning messages. Personally I prefer one message as it is more compact and fits quite well in both cases, but I have no strong fillings with separate message for each case. > > Will any more fine-tuning be useful? Could you elaborate it. Regards Andrzej > > Regards, > Markus > -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH v3] coccinelle: tests: unsigned value cannot be lesser than zero
> v3: added bool type I would appreciate a bit more feedback for my concerns around your evolving approach. * Reuse of "long int"? * Splitting of the suggested SmPL rule so that each source code check will be connected with appropriate warning messages. Will any more fine-tuning be useful? Regards, Markus -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[PATCH v3] coccinelle: tests: unsigned value cannot be lesser than zero
Code comparing unsigned variables with zero using operators < or >= does not make sense. It is always false or true, respectively. However, its presence often indicates bugs in the code. gcc can detect it also using -Wtype-limits switch, but it warns also in correct cases, making too much noise. Signed-off-by: Andrzej HajdaAcked-by: Julia Lawall --- v3: added bool type v2: added --all-includes option --- .../tests/unsigned_lesser_than_zero.cocci | 37 ++ 1 file changed, 37 insertions(+) create mode 100644 scripts/coccinelle/tests/unsigned_lesser_than_zero.cocci diff --git a/scripts/coccinelle/tests/unsigned_lesser_than_zero.cocci b/scripts/coccinelle/tests/unsigned_lesser_than_zero.cocci new file mode 100644 index 000..70e71c8 --- /dev/null +++ b/scripts/coccinelle/tests/unsigned_lesser_than_zero.cocci @@ -0,0 +1,37 @@ +/// Unsigned variables cannot be lesser than zero. Presence of such checks +/// can indicate incorrect variable type or just unnecessary code. +/// +// 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 depends on context || org || report@ +position p; +typedef bool, u8, u16, u32, u64; +{unsigned char, unsigned short int, unsigned int, unsigned long, unsigned long long, size_t, bool, u8, u16, u32, u64} v; +@@ + +( +*v@p < 0 +| +*v@p >= 0 +) + +@script:python depends on org@ +p << r.p; +@@ + +msg = "WARNING: Unsigned value cannot be lesser than zero" +coccilib.org.print_todo(p[0], msg) + +@script:python depends on report@ +p << r.p; +@@ + +msg = "WARNING: Unsigned value cannot be lesser than zero" +coccilib.report.print_report(p[0], msg) -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH v3] coccinelle: tests: unsigned value cannot be lesser than zero
>> * Reuse of "long int"? > If you mean adding int to 'unsigned long [long]' types, it does not work. I am surprised. > For some reason it works only without adding int after long. The Coccinelle software should support the term "generic_ctype" from the SmPL grammar so far, shouldn't it? http://coccinelle.lip6.fr/docs/main_grammar005.html#ctype >> * Splitting of the suggested SmPL rule so that each source code check >> will be connected with appropriate warning messages. > Personally I prefer one message as it is more compact It might look convenient to combine a few source code checks. > and fits quite well in both cases, I got an other impression. > but I have no strong fillings with separate message for each case. * v@p < 0 Find places where this condition will always be false. *v@p >= 0 Find places where this condition will always be true. Will it help to distinguish these special cases also in your SmPL script strictly? Regards, Markus -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/