Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's such macro for?

Tags:

c++

macros

#define ValidateReadPtr(p,cb) 0

I can't think of a use case for this kind of macro,what about you?

like image 467
Alan Avatar asked Dec 10 '22 13:12

Alan


2 Answers

I can only find the ValidateReadPtr() macro in the wxdebug.h header for the Windows Mobile SDK (even though MSDN indicates it's part of the DirectShow APIs).

In wxdebug.h it's defined as:

#define ValidateReadPtr(p,cb) \
    {if(IsBadReadPtr((PVOID)p,cb) == TRUE) \
        DbgBreak("Invalid read pointer");}

I suspect that in your project it's defined as 0 for one or both of the following reasons:

  • to make the code that uses it compile even when the wxdebug.h header isn't available (ie., not using the Windows Mobile SDK)
  • IsBadReadPtr() is now considered a dangerous API that shouldn't be used. The docs for IsBadreadPtr() say, "Important This function is obsolete and should not be used. Despite its name, it does not guarantee that the pointer is valid or that the memory pointed to is safe to use. For more information, see Remarks...". And Raymond Chen wrote an article about the problems with IsBadReadPtr(): IsBadXxxPtr should really be called CrashProgramRandomly
like image 57
Michael Burr Avatar answered Dec 12 '22 02:12

Michael Burr


It was probably used for something else, and then was redefined as 0.

That's the beauty of macros, you can use them in your code, and then, one simple redefinition is good enough to change all occurrences of that macro in the code.

What's probably happening now is the programmer wants that validation (ValidateReadPtr) always return FALSE (0 in C/C++).

like image 44
Pablo Santa Cruz Avatar answered Dec 12 '22 04:12

Pablo Santa Cruz