...
Ensure that restrict
-qualified source and destination pointers do not reference overlapping objects when invoking library functions. The standard For example, the following C Standard library functions shown below are examples of ones that copy memory from a source object referenced by a restrict
-qualified pointer to a destination object that is also referenced by a restrict
-qualified pointer:
Standard C | Annex K |
---|---|
strcpy() | strcpy_s() |
strncpy() | strncpy_s() |
strcat() | strcat_s() |
strncat() | strncat_s() |
memcpy() | memcpy_s() strtok() |
strtok_s() |
If the objects referenced by arguments to functions overlap (meaning the objects share some common memory addresses), the behavior is undefined. See also undefined behavior 68 in Appendix J of the C Standard. The result of the functions is unknown and data may be corrupted. As a result, these functions must never be passed pointers to overlapping objects. If data must be copied between objects that share common memory addresses, a copy function guaranteed to work on overlapping memory, such as memmove()
, should be used.
...