memcpy 拷贝常量字符串越界的问题
有如下程序段:
char buf[30] = {0};
memcpy(buf, "hello", 30);
这种用法虽然不会导致目的buffer 溢出,但是却会访问到源数据之外的memory. 这种用法是否存在什么潜在的风险?
memcpy 原型如下:
void *memcpy(void *dest, const void *src, size_t n);
DESCRIPTION
The memcpy() function copies n bytes from memory area src to memory area dest. The memory areas must not overlap. Use memmove(3) if
the memory areas do overlap.