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 == ...);
```


> On 8 Feb 2020, at 11:44, Markus Elfring <[email protected]> wrote:
> 
> Can the following transformation variants be also helpful?
> 
> 
>> @@
>> type T;
>> expression source;
>> @@
>> 
>> - REQUIRE(((T *)source) != NULL);
>> + REQUIRE(source != NULL);
> 
> REQUIRE((
> -         (T*)
>          source) != NULL);

Thanks, that’s helpful. I’ll use that.

>> @@
>> 
>>  REQUIRE(source != NULL);
>>  ...
>>  REQUIRE((
>> - (T *)
>> + (dns_rdatacommon_t *)
> 
> (
> -T
> +dns_rdatacommon_t
> *)


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

Reply via email to