mercredi 3 novembre 2021

Pointer parameter is not used to modify in virtual function (MISRA)

I have a virtual function (not pure) like this:

In the header:

  virtual int8_t insertData(
    uint8_t* AddressInput,
    myStruct* cpstrData,
    );

This function can be implemented on child classes but is not mandatory that all of them do it.

Because of this, the base class has an implementation that goes like this:

int8_t myClass::insertData(
    uint8_t* AddressInput,
    myStruct* cpstrData,
  )
{
  int8_t s8Err = SUCCESS;
  (void)(*AddressInput); //I also tried: (void)AddressInput;
  (void)(*cpstrData);    //I also tried: (void)cpstrData;
  return s8Err;
}

This works OK BUT a MISRA checker is giving me the following error (for both pointers): https://rules.sonarsource.com/c/RSPEC-995

Pointer parameter is not used to modify the addressed object but is not declared as a pointer to const

In the children classes this pointer is actually used to modify the addressed object, is there a way to tell the program that this pointers point to const only in the base class? Or a workaround similar to (void)thisVariable thatworks on the pointed objects?

Aucun commentaire:

Enregistrer un commentaire