Is memcpy() safe when copy some content larger than dst?
Is it safe when the request_token.size()
is larger than LEN
?
char dst[LEN];
mem开发者_JAVA百科cpy(dst, request_token.c_str(), request_token.size());
No, it's not safe; you'll cause a buffer overflow. The reason is, memcpy
has no way to know the size of your target buffer, other than the size you pass in the third argument.
No, definitely not, that will lead to buffer overrun and trigger undefined behavior which will lead to all sorts of bad things, included but not limited to data corruption and program crashing.
No, it is not safe. Read this: http://msdn.microsoft.com/en-us/library/dswaw1wk(VS.80).aspx
Use memcpy_s(): http://msdn.microsoft.com/en-us/library/dswaw1wk(VS.80).aspx
No, you will end up in trying to write to invalid memory locations which causes undefined behavior.
精彩评论