>I never said memcpy() wasn't standard.
The implication was there. Just think of it as adding to your answer rather than correcting you.
>If not, you may very well be playing with fire to try reading
>(or writing) past the end of memory you have not allocated.
I don't even know what you're trying to say anymore. Perhaps if you gave some examples that show your point more clearly. It seems like you're trying to make strncpy somehow better than memcpy because the count represents an "at most" count rather than a hard count.
In that case, owning the source is irrelevant provided you use a sane value for the count argument. For example, the count would be acquired by calling strlen on the source and then verifying that the destination is big enough to handle it. Whether you're using memcpy or strncpy (or strcpy for that matter), it's wise to get your destination size right, which typically means learning the size of the source.
>However, it stops reading the source when it hits the end of the string
Yes, that's typical of the str* functions, whereas the mem* functions take a count rather than assuming a null terminated string for the source.
>The strtol() has the same validation problems as stroi().
No, it doesn't. It has completely defined and predictable behavior if there's a conversion error, the location and type of which you can pinpoint and recover from with ease. atoi isn't even close to strtol in robustness.
>Just because it returns something different...
And sets errno, and sets a pointer to where the conversion failed, and the return value tells you what kind of overflow (if any) occurred without invoking undefined behavior. The error detection potential of strtol is quite good.
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Offline 11,807 posts
since Sep 2004