SHARE
TWEET

Untitled

a guest Sep 17th, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. int main()
  6. {
  7.     char * string = malloc(14);
  8.     strcpy(string, "Hello World!\n");
  9.     char * ptr = string;
  10.     printf("%s is at %p\n", string, string);
  11.     free(string);
  12.     printf("%s is at %p\n", ptr, ptr);
  13. //  char * newstring = malloc(5);
  14. //  strncpy(newstring, "  Bye", 5);
  15.     strncpy(ptr, "  Bye", 5);
  16.     printf("%s is at %p\n", ptr, ptr);
  17.     return 0;
  18. }
  19.  
  20. /* This pleases me way more than it should
  21.  *
  22.  * Hello World!
  23.  * is at 0x7ffae04006a0
  24.  * Hello World!
  25.  * is at 0x7ffae04006a0
  26.  * Bye   World!
  27.  * is at 0x7ffae04006a0
  28.  *
  29.  *
  30.  * Next thing I should try - two threads, does one use the other's freed memory
  31.  *             - start two processes, does one use the other's freed memory
  32.  */
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top