Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rule M16.10
#1
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.
<t></t>
Reply
#2
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.
<t></t>
Reply
#3
Thanks for this reply, the problem is now fixed.
Best Regards.
Philippe
<t></t>
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)