Last active
November 5, 2017 13:55
-
-
Save sitano/0372e516aadf7bbecabc33f0b6516704 to your computer and use it in GitHub Desktop.
undefined behavior with realloc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
int main(void) | |
{ | |
int* p = (int *)malloc(sizeof(int)); | |
int* q = (int *)realloc(p, sizeof(int)); | |
*p = 1; | |
*q = 2; | |
if (p == q) | |
{ | |
printf("%d %d\n", *p, *q); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://stackoverflow.com/questions/26072752/realloc-dangling-pointers-and-undefined-behavior
https://stackoverflow.com/questions/40065322/realloc-lifetime-and-ub
http://www.open-std.org/jtc1/sc22/wg14/www/docs/summary.htm#dr_400
http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_260.htm
https://www.youtube.com/watch?v=g7entxbQOCc#t=25m56s
https://www.youtube.com/watch?v=v1COuU2vU_w