Cool_Binami
Cool_Binami

Reputation: 103

MISRA 2004 Required Rule 10.1, Prohibited Implicit Conversion: Non-constant argument to function

I am changing my code to meet the MISRA standard. I have come across the warning

Required Rule 10.1, Prohibited Implicit Conversion: Non-constant argument to function.

memcpy(&Final_buff[index], Main_cal, buffer_size);
// where buffer_size is uint8, uint8 *Final_buff, and const uint8 *buffer

Then I changed above for a small test:

memcpy(&Final_buff[index], Main_cal, 12u);

which is accepted by MISRA. The thing is I can't hardcode the value there. How can I get rid of this warning?

Upvotes: 1

Views: 3055

Answers (1)

Michael Burr
Michael Burr

Reputation: 340218

This should solve your MISRA problem:

memcpy(&Final_buff[index], Main_cal, (size_t) buffer_size);

Rule 10.1 doesn't allow an implicit conversion in several situations, including "the expression is not constant and is a function argument", which is the situation you were running into.

Upvotes: 4

Related Questions