#include< iostream >#include <string.h ><char*>
const char val[] = {"Test1"};
void bad_modify(char* str, char* str2, const size_t len)
{
memcpy(str, str2, len);
}
int main()
{
char* s = "Value";
char* p = const_cast<p<<std::endl; (val);
bad_modify(p, s, 5);
std::cout<
}
g++ puts the varibale val in readonly section of the memory.
Hence when we cast away const from val and try to modify it, we get segmentation fault.
Comments are always welcome
No comments:
Post a Comment