[previous] 2845 [next] Constant: Maximum number of characters to be written is larger than the target buffer size.
Arrays

Certain standard library functions specify a maximum number (M) of characters to be written to a char array (A).

function A parameter numberM parameter number
asctime_s 12
ctime_s 12
snprintf 12
snprintf_s 12
strcpy_s 12
strncat 13
strncat_s 12
strncat_s 14
strncat_s 34
strncpy 13
strncpy_s 14

This message is issued whenever a constant expression is used for M and the size of object A is smaller than M. This may result in an access outside the bounds of A.

For example:


/*PRQA S 1-9999 ++*/
/*PRQA S 2845 --*/

#include <string.h>

extern char a[10];
extern char b[11];

void foo (void)
{
  strncpy (a, b, sizeof (b));   /* 2845 */
}


MISRA C:2012 Rules applicable to message 2845:

Dir-4.1  (Required) Run-time failures shall be minimized


See also:

QA·C Source Code Analyser 8.1
MISRA C:2012 Compliance Module 1.0
© 2012 Programming Research.
www.programmingresearch.com
Personality Groups | Glossary | Message Index | MISRA C:2012 Rule Index Contents