From 21c4be47790c230cf5a321aeabb5c07ad57f0522 Mon Sep 17 00:00:00 2001 From: Ryan Date: Wed, 17 Aug 2016 13:25:32 -0600 Subject: Remove undefined behavior (#2332) --- c.html.markdown | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/c.html.markdown b/c.html.markdown index babf0954..92f07fe2 100644 --- a/c.html.markdown +++ b/c.html.markdown @@ -449,7 +449,8 @@ int main (int argc, char** argv) int size = 10; int *my_arr = malloc(sizeof(int) * size); // Add an element to the array - my_arr = realloc(my_arr, ++size); + size++; + my_arr = realloc(my_arr, sizeof(int) * size); my_arr[10] = 5; // Dereferencing memory that you haven't allocated gives -- cgit v1.2.3