MISRA Discussion Forums

Full Version: Rule M16.10
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello all,

I'm using the Misra 2004:C rules for the 1st time (e.g. I'm a newbie) and I got several errors linked to the rule M16.10 when I'm using the strncpy function like that:

Code:
strncpy(MyStr1,MyConstStr, sizeof(MyConstStr);

I've fixed this error by adding a pointer to the code which is not used.

Code:
char *MyPtr;
MyPtr = strncpy(MyStr1,MyConstStr, sizeof(MyConstStr);

So my question is:
For the functions like strncpy, memset and others functions of the same style, do we need to fix the misra error or do we have to justify it plainly?

By advance, thanks for your help.
From ISO C standard:

Quote:The strncpy function returns the value of s1.

So, no error information to test and hence no violation of 16.10.

If you upgrade to MISRA C 2012 you can use this explicit exception for function return values:

Code:
(void)strncpy(MyStr1,MyConstStr, sizeof(MyConstStr);

I did not find a corresponding entry in the obsolete 2004 standard.
Thanks for this reply, the problem is now fixed.
Best Regards.
Philippe