Replacing the type casting
Can the following transformation variants be also helpful?
Quoted 7 lines
@@
type T;
expression source;
@@-
REQUIRE(((T *)source) != NULL);
+ REQUIRE(source != NULL);
REQUIRE((
- (T*)
source) != NULL);
Quoted 3 lines
@@
type T;
type R;
type T;
Quoted 3 lines
identifier common, rdtype;
T *target;
expression source;
typedef dns_rdatacommon_t;
Quoted 7 lines
@@
REQUIRE(source != NULL);
...
REQUIRE((
- (T *)
+ (dns_rdatacommon_t*)
(
-T
+dns_rdatacommon_t
*)
Will any constraints become relevant for the deleted data types?
Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Hi Markus,
I ended up with:
``` @@ type T; expression source; @@ - REQUIRE(((T *)source) != NULL); + REQUIRE(source != NULL); @@ type T; typedef dns_rdatacommon_t; identifier common, rdtype; identifier source; @@ REQUIRE(( - (T *)source + (dns_rdatacommon_t *)source )-> - common. rdtype == ...); @@ type T; typedef dns_rdatacommon_t; identifier common, rdclass; identifier source; @@ REQUIRE(( - (T *)source + (dns_rdatacommon_t *)source )-> - common. rdclass == ...); ```
Quoted 10 lines · Markus Elfring
Can the following transformation variants be also helpful?
Quoted 5 lines
@@
type T;
expression source;
@@
Quoted 6 lines
Quoted 2 lines
-
REQUIRE(((T *)source) != NULL);
+ REQUIRE(source != NULL);REQUIRE((
- (T*)source) != NULL);
Thanks, that’s helpful. I’ll use that.
Quoted 11 lines
Quoted 7 lines
@@
REQUIRE(source != NULL);
...
REQUIRE((
- (T *)
+ (dns_rdatacommon_t*)(
(quoted diff) +1
-1-T +dns_rdatacommon_t
Quoted 1 line
*)
This cannot be done, as I need to convert only .common members, as the more specific data types include dns_rdatacommon_t as a first member of the struct (a header), but they usually contain more fields, f.e.:
REQUIRE(type == dns_rdatatype_nsec);
REQUIRE((source) != NULL);
REQUIRE(((dns_rdatacommon_t *)source)->rdtype == type);
REQUIRE(((dns_rdatacommon_t *)source)->rdclass == rdclass);
REQUIRE(((dns_rdata_nsec_t *)source)->typebits != NULL ||
((dns_rdata_nsec_t *)source)->len == 0);Ondrej
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Quoted 5 lines
Quoted 3 lines
REQUIRE((
- (T*)source) != NULL);Thanks, that’s helpful.
Thanks for such a view on the suggested transformation approach.
Quoted 10 lines
Quoted 8 lines
Quoted 3 lines
REQUIRE((
- (T *)
+ (dns_rdatacommon_t*)(
(quoted diff) +1
-1-T +dns_rdatacommon_t*)
This cannot be done,
I propose to take another look at how many adjustments such a type cast will need actually.
Will the replacement of the data type be sufficient at this place of SmPL code?
Quoted 1 line
as I need to convert only .common members, …
This concern can be added to the referenced change pattern.
Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci