In C, what will happen if I supply a signed integer especifically a negative integer as the 3rd argument to the memcpy function?
Example:
memcpy(destBuf, source, -100*sizeof(source))
Will the result of -100*sizeof(source) be interpreted by memcpy as unsigned?
Thanks!
the last parameter is unsigned. so by doing -100 * sizeof( source ) you’ll get a huge number (That will wrap around, ie overflow).
This is equivalent to doing “4,294,967,196 * sizeof( source )”.
Edit: Actually thats wrong I just realised. It will do -100 * sizeof( source ) and then convert it to an unsigned. For example if sizeof( source ) is 4 then it will convert -400 to unsigned and give you 0xFFFFFE70 (4,294,966,896).