Reputation: 103
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
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