Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
743 B

  1. // Copyright (c) 1998 Microsoft Corporation
  2. // ValidP.h --- An inline function to test for valid pointers
  3. #ifndef __VALID_P__
  4. #define __VALID_P__
  5. // The debug version checks for Null pointers and pointers to unreadable/unwriteable data.
  6. // (NOTE: only the first byte pointed to is checked)
  7. // The non-debug version just checks for Null pointers.
  8. template <class T>
  9. inline BOOL Validate(T *p)
  10. {
  11. #ifdef _DEBUG
  12. return (p != NULL) && !IsBadReadPtr(p, 1) && !IsBadWritePtr(p, 1);
  13. #else
  14. return p != NULL;
  15. #endif
  16. }
  17. /* Use:
  18. Foo *pFoo;
  19. //
  20. // stuff...
  21. //
  22. if (Validate(pFoo))
  23. {
  24. // do stuff with the pointer
  25. }
  26. else
  27. {
  28. // don't do stuff with the pointer
  29. }
  30. */
  31. #endif // __VALID_P__