User forums > Help

[SOLVED] No error when using pointer with no address

(1/1)

Mishkafofer:
Hi all,
I saw a code that according to lecturer in UNI should create an error. I attached a print screen from lecturer pptx where he posted an error message from Visual Studio. I was expecting to get similar error from CB but didn't. I not sure if it's CB issue or compiler. I use GCC.
The code is very simple. The IDE is expected to give error when trying to access pointer with garbage address.
Here is the code:
https://pastebin.com/yC5AcGiF

Mishkafofer:
I am new to this forum, i am not sure if using paste bin is appropriate. Anyway i preferred paste bin due to code highlights.
Here is the code directly.

--- Code: ---#include <stdio.h>

{
    int *p1 = NULL, *p2;
    printf("%p", p1); //points to NULL
    printf("%p", p2); //point nowhere, should crash but CB ignores it.
}
--- End code ---

oBFusCATed:
If you're on linux or mac you can achieve the same error detection using valgrind or some of the sanitizers (address or memory).

And yes this is more a feature of the compiler/runtime than something codeblocks provides.

sodev:
This is a feature of the MSVC runtime that does some checks at runtime in debug mode and displays these dialogs, i doubt gcc offers something like that.

And your code example should not crash, you just output the value of that uninitialized pointer, this doesnt crash but just displays its random value. It would very likely crash if you would dereference that pointer, unless by chance the random value points to a valid address you have access to ;)

Navigation

[0] Message Index

Go to full version