Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I check if a variable is in memory 0xfdfdfdfd in C?

Tags:

c

memory

I have a code that checks the condition of a variable.

Sometimes this variable is in memory 0xfdfdfdfd, and of course it cannot read from there.

If the variable was null, I would

 if(!variable)
 {
     //report error or skip...
 }
 else 
 {
     //do stuff with the variable...
 }

but apparently 0xfdfdfdfd means that there is a variable, and I just cannot access it.

Is there a check that I can use (like for null), so I do not try to mess with the variable when I cannot access it?

like image 914
Bruno Lubascher Avatar asked Dec 18 '25 17:12

Bruno Lubascher


2 Answers

0xFDFDFDFD is a magic number used for helping debugging. You can find a reference on wikipedia Magic Numbers, and also useful information in this SO answer and in this other SO answer:

There you can see that:

FDFDFDFD Used by Microsoft's C/C++ debug malloc() function to mark "no man's land" guard bytes before and after allocated heap memory[15]

This could mean your are trying to read before or after a block of memory allocated on the heap.

(My first inner thought though was to think that your variable had not been initialized, but I don't know these magic number codes by heart)

You should correct this bug ! And not avoid it like you are wanting to.

like image 190
Stephane Rolland Avatar answered Dec 20 '25 08:12

Stephane Rolland


0xfdfdfdfd is a value your compiler introduced into your debugging so you can see where your program still has bugs. You either did not properly initialize this variable or your did delete it and try to access it anyway. Do not check for this value, instead properly debug and fix your program.

like image 27
nvoigt Avatar answered Dec 20 '25 08:12

nvoigt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!