Hello,
I've run into a new set of false positives in my quest to remove casts
to self:
If the type of a field is unknown then the cast to int will be kept
(int)s->unknown
But if that field is involved in an arithmetic operation with a numeric
constant and the result gets casted to int then the cast gets
erroneously removed:
(int)(s->unknown / 1000)
That happens only for fields as a the cast will be kept in for variables:
(int)(unknown / 1000)
Also if the type of the field is known and doesn't matches then the cast
is correctly kept.
Test case is attached.
thanks
bye
michael
@ disable drop_cast @
type T;
T E;
@@
- (T)
E
struct _sk {
int i;
long l;
};
int foo(int i, long l, bar b, struct _sk *sk, struct _su *su)
{
int tmp = (int)i;
tmp += (int)(i / 1000);
tmp += (int)l;
tmp += (int)(l / 1000);
tmp += (int)b;
tmp += (int)(b / 1000);
tmp += (int)sk->i;
tmp += (int)(sk->i / 1000);
tmp += (int)sk->l;
tmp += (int)(sk->l / 1000);
tmp += (int)su->l;
tmp += (int)(su->l / 1000);
return tmp;
}
--- type.c
+++ /tmp/cocci-output-10499-bbfa36-type.c
@@ -5,17 +5,17 @@ struct _sk {
int foo(int i, long l, bar b, struct _sk *sk, struct _su *su)
{
- int tmp = (int)i;
- tmp += (int)(i / 1000);
+ int tmp = i;
+ tmp += (i / 1000);
tmp += (int)l;
tmp += (int)(l / 1000);
tmp += (int)b;
tmp += (int)(b / 1000);
- tmp += (int)sk->i;
- tmp += (int)(sk->i / 1000);
+ tmp += sk->i;
+ tmp += (sk->i / 1000);
tmp += (int)sk->l;
tmp += (int)(sk->l / 1000);
tmp += (int)su->l;
- tmp += (int)(su->l / 1000);
+ tmp += (su->l / 1000);
return tmp;
}
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci