Skip to content

Instantly share code, notes, and snippets.

@samdmarshall
Forked from anonymous/fuck.cpp
Created August 8, 2013 16:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samdmarshall/6186440 to your computer and use it in GitHub Desktop.
Save samdmarshall/6186440 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string>
using namespace std;
int main(){
static const char* val1 = "hello";
const char* val2 = "hello";
const string val3 = "hello";
char* pointer = (char*)val3.c_str();
printf("\nbefore: %s, %s, %s", val1, val2, (char*)pointer);
printf("\nbefore: %p, %p, %p", (void*)val1, (void*)val2, pointer);
char* modifyingVal2 = "fuck";
memset(pointer, 0, strlen(val3.c_str()));
memcpy((void*)val3.c_str(), modifyingVal2, strlen(modifyingVal2));
printf("\nafter: %s, %s, %s", val1, val2, val3.c_str());
printf("\nafter: %p, %p, %p", (void*)val1, (void*)val2, (void*)val3.c_str());
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment