fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct Mystruct {
  5. int chunk[8];
  6. struct Mystruct *next;
  7. struct Mystruct *prev;
  8. } Mystruct;
  9.  
  10. typedef struct {
  11. Mystruct *first;
  12. Mystruct *last;
  13. } Container;
  14.  
  15.  
  16. int main (void)
  17. {
  18. // We create the list
  19. Container *container = (Container*) malloc(sizeof(Container*));
  20. container->first = (Mystruct*) malloc(sizeof(Mystruct*));
  21. container->last = container->first;
  22.  
  23. container->first->next = NULL;
  24. container->first->prev = NULL;
  25.  
  26.  
  27. // Now let's check the adresses
  28. printf("In main we've got \ncontainer->first: %p \ncontainer->last %p \n\
  29. container: %p\n\n", container->first, container->last, container);
  30.  
  31.  
  32.  
  33. // We try to update a value of chunk[0]
  34. *(container->first->chunk) = 5;
  35.  
  36.  
  37.  
  38. // And get corrupted pointers
  39. printf("In main after change we've got \ncontainer->first: %p \ncontainer->last %p \n\
  40. container: %p\n", container->first, container->last, container);
  41.  
  42. return 0;
  43. }
Success #stdin #stdout 0s 2244KB
stdin
Standard input is empty
stdout
In main we've got 
container->first: 0x83a2018 
container->last 0x83a2018 
container: 0x83a2008

In main after change we've got 
container->first: 0x83a2018 
container->last 0x83a2018 
container: 0x83a2008