There is a phrase that keeps popping up in Annex K of the C standard (bounds-checking interfaces):
....copying shall not take place between objects that overlap.
Considering, for example, strcpy_s( char * restrict s1, rsize_t s1max, char const * restrict s2 )
, in which s1max
specifies the maximum capacity of s1
to enable the bounds checking.
What exactly would be "the object" s1
at this point, which must not overlap with "the object" s2
?
Would that be...
- s1[0]..s1[s1max] (to the end of the buffer, i.e. the memory object),
or
- s1[0]..s1[strnlen( s1, s1max )] (to the end of the string, i.e. the string object)?
If it is the former, I wonder about the lack of consistency, as I do not know the size of the buffer that is s2, and would have to apply a different definition of "the object".
If it is the latter, I wonder if it doesn't break "the promise" that is given, as conceivably the source string and the eventual (post-copy) destination string could overlap if the source string is longer than the original one.
What is the intention / the intended definition of "object" here?