...
Standard Library Functions
Following is an incomplete list are lists of C library functions to which this rule applies.
...
The following standard library functions take a pointer argument and a size argument, with the constraint that the pointer must point to a valid memory object of at least the number of bytes or wide characters (as appropriate) indicated by the size argument.
fgets() fread | fgetws() | mbstowcs() *1 fwrite | wcstombs() *1 | |
mblenmbrtoc16()2 | memchrmbrtoc32()2 | memsetmbsrtowcs()1 | fgetwswcsrtombs()1 | |
wmemchrmbtowc()2 | wmemsetmbrtowc()1 | mbrlenmblen() | tmpnam_smbrlen() gets_s | |
memchr() | getenv_swmemchr() | memset _s() strerror_s | wmemset() strnlen_s | |
strftime() | wcsftime() | strxfrm()1 | wcsxfrm()1 | |
strncat()2 | wcsncat()2 | snprintf() | vsnprintf() | |
swprintf | asctime_s() | ctime_svswprintf() | wcscpy_ssetvbuf() | wcsncpytmpnam_s() |
snprintf_s() | wmemmovesprintf_s() | wcscatvsnprintf_s() | wcsncatvsprintf_s() | |
gets_s() |
|
|
Library Functions That Take Two Pointers and an Integer
The following standard library functions take two pointer arguments and a size argument, with the constraint that both pointers must point to valid memory objects of at least the number of bytes or wide characters as appropriate, indicated by the size argument.
getenv_s() | wctomb_s() | mbstowcs_s()3 | |
wcstombs_s()3 | memcpy_s()3 | memmove_s()3 | strncpy_s()3 |
strncat_s()3 | strtok_s()2 | strerror_s() | strnlen_s() |
asctime_s() | ctime_s() | snwprintf_s() | swprintf_s() |
vsnwprintf_s() | vswprintf_s() | wcsncpy_s()3 | wmemcpy_s()3 |
wmemmove_s()3 | wcsncat_s()3 | wcstok_s()2 | wcsnlen_s() |
wcrtomb_s() | mbsrtowcs_s()3 | wcsrtombs_s()3 |
1 Take two pointers and an integer, but the integer only specifies the length of the output buffer. not the input buffer.
2 Takes two pointers and an integer, but the integer only specifies the length of the input buffer, not the output buffer.
3 Takes two pointers and two integers; each integer corresponds to the length of one of the pointers.
Library Functions That Take Two Pointers and an Integer
The following standard library functions take two pointer arguments and a size argument, with the constraint that both pointers must point to valid memory objects of at least the number of bytes or wide characters as appropriate, indicated by the size argument.
| wmemcpy() | memmove() | wmemmove() |
strncpy() | wcsncpy() | memcmp() | wmemcmp() |
strncmp() | wcsncmp() | strcpy_s() | wcscpy_s() |
strcat_s() | wcscat | ||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| wcsrtombs_s() |
Library Functions That Take a Pointer and Two Integers
The following standard library functions take a pointer argument and two size arguments, with the constraint that the pointer must point to a valid memory object containing at least as many bytes as the product of the two size arguments.
bsearch ()qsort() | bsearch_s () |
|
Standard Memory Allocation Functions
The following are the standard memory allocation functions that take a size integer argument and return a pointer.
|
|
|
|
Other Library Functions
memcpy() | memmoveqsort() vsnprintf | qsort_s() |
vswprintffread() | swprintffwrite() strftime | memset_s()1 |
|
|
|
*Both functions take more than one size_t
argument. In such cases, the compliant code must be consistent with the purpose of these arguments. For example, in the case of fread()
:
Code Block |
---|
size_t fread(void *ptr, size_t size, size_t count, FILE *stream)
|
...
1 Takes a pointer and two size-related integers; the first size-related integer parameter specifies the size of the buffer, the second size-related integer parameter specifies the number of bytes to write within the buffer.
Standard Memory Allocation Functions
The following are the standard memory allocation functions that take a size integer argument and return a pointer.
|
|
|
|
Description
To guarantee that a library function does not construct an out-of-bounds pointer, programmers must heed the following rules when using functions that operate on pointed-to regions. These rules assume that func
is a function, p
and q
are pointers, and n
is an integer.
...
[ISO/IEC TS 17961] | Programming Languages,Their Environments and System Software Interfaces |
...