2

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?

SanderDN
  • 496
  • 6
  • 19
Bruno Lubascher
  • 2,071
  • 14
  • 19
  • 1
    Can you explain clearly??? – Karthikeyan.R.S Jan 09 '15 at 12:34
  • assuming `variable` has type `int` ==> `if (&variable == (int*)0xfdfdfdfd) { /* whatever */ }` – pmg Jan 09 '15 at 12:35
  • 0xfdfdfdfd is mainly when the object is deleted... – Robert Jan 09 '15 at 12:35
  • There are the high reputation guys voting to close this question without giving the OP a chance to explain... – Iharob Al Asimi Jan 09 '15 at 12:36
  • 5
    This sounds like you have buffer overflow somewhere or you're using an unitialized variable. Without the code in question we can't tell, though. – DarkDust Jan 09 '15 at 12:36
  • And there it is, there are two answer for this question as it is, it's just that some people are eager to use their privileges, I'm starting to think, this site is not useful anymore, and that the useful answers are to old questions because sometimes you don't even have a chance to answer when someone who doesn't even know what the question is about, just closed it. – Iharob Al Asimi Jan 09 '15 at 12:39

2 Answers2

13

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.

Community
  • 1
  • 1
Stephane Rolland
  • 38,876
  • 35
  • 121
  • 169
6

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.

nvoigt
  • 75,013
  • 26
  • 93
  • 142