The C11 Annex C Standard, Annex K (normative), "Bounds-checking interfaces" [ISO/IEC 9899:2011], defines alternative versions of standard string-handling functions designed to be safer replacements for existing functions. For example, it defines the strcpy_s()
, strcat_s()
, strncpy_s()
, and strncat_s()
functions as replacements for strcpy()
, strcat()
, strncpy()
, and strncat()
, respectively.
The C11 Annex The Annex K functions were created by Microsoft to help retrofit its existing legacy code base in response to numerous, well-publicized security incidents over the past decade. These functions were subsequently proposed to the international standardization working group for the programming language C (ISO/IEC JTC1/SC22/WG14) for standardization.
...
The signature is similar to strcpy()
but takes an extra argument of type rsize_t
that specifies the maximum length of the destination buffer. Functions that accept parameters of type rsize_t
diagnose a constraint violation if the values of those parameters are greater than RSIZE_MAX
. Extremely large object sizes are frequently a sign that an object's size was calculated incorrectly. For example, negative numbers appear as very large positive numbers when converted to an unsigned type like size_t
. For those reasons, it is sometimes beneficial to restrict the range of object sizes to detect errors. For machines with large address spaces, C11 Annex K the C Standard, Annex K, recommends that RSIZE_MAX
be defined as the smaller of the size of the largest object supported or (SIZE_MAX >> 1)
, even if this limit is smaller than the size of some legitimate, but very large, objects. See also INT01-C. Use rsize_t or size_t for all integer values representing the size of an object.
...