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

A definite anomaly has been detected.

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 non constant expression is used for M and its value is always greater than the size of object A. This may result in an access outside the bounds of A.

For example:


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

#include <string.h>

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

void foo (int m)
{
  if (m > sizeof (a))
  {
    strncpy (a, b, m);   /* 2846 */
  }
}

See also:

QA·C Source Code Analyser 8.1.2
© 2013 Programming Research.
www.programmingresearch.com
Personality Groups | Glossary | Message Index Contents