Source code of Windows XP (NT5)
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.

57 lines
2.2 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // Windows 2000 Active Directory Service WMI providers
  4. //
  5. // Microsoft Windows
  6. // Copyright (C) Microsoft Corporation, 1992 - 2000
  7. //
  8. // File: common.h
  9. //
  10. // Contents: Common macros and definitions
  11. //
  12. // History: 24-Mar-00 EricB created
  13. //
  14. //-----------------------------------------------------------------------------
  15. #define BAD_IN_STRING_PTR(p) (NULL == p || IsBadStringPtr(p,0))
  16. #define BAD_IN_STRING_PTR_OPTIONAL(p) (NULL != p && IsBadStringPtr(p,0))
  17. #define BAD_IN_READ_PTR(p,size) (NULL == p || IsBadReadPtr(p,size))
  18. #define BAD_WRITE_PTR(p,size) (NULL == p || IsBadWritePtr(p,size))
  19. template<class T>
  20. bool
  21. BAD_IN_MULTISTRUCT_PTR(T* p, size_t count)
  22. {
  23. return BAD_IN_READ_PTR(p, count * sizeof(T));
  24. }
  25. #define BAD_IN_STRUCT_PTR(p) BAD_IN_MULTISTRUCT_PTR(p,1)
  26. template<class T>
  27. bool
  28. BAD_OUT_MULTISTRUCT_PTR(T* p, size_t count)
  29. {
  30. return BAD_WRITE_PTR(p, count * sizeof(T));
  31. }
  32. #define BAD_OUT_STRUCT_PTR(p) BAD_OUT_MULTISTRUCT_PTR(p,1)
  33. #define ASSERT_AND_RETURN {ASSERT(false); return WBEM_E_INVALID_PARAMETER;}
  34. #define ASSERT_AND_BREAK {ASSERT(false); break;}
  35. #define BREAK_ON_FAIL if (FAILED(hr)) ASSERT_AND_BREAK;
  36. #define BREAK_ON_NULL(x) if (!(x)) ASSERT_AND_BREAK;
  37. #define BREAK_ON_NULL_(x, h, c) if (!(x)) {h = c; ASSERT_AND_BREAK;}
  38. #define WBEM_VALIDATE_READ_PTR(p,size) \
  39. if (BAD_IN_READ_PTR(p,size)) ASSERT_AND_RETURN;
  40. #define WBEM_VALIDATE_IN_STRUCT_PTR(p) \
  41. if (BAD_IN_STRUCT_PTR(p)) ASSERT_AND_RETURN;
  42. #define WBEM_VALIDATE_IN_MULTISTRUCT_PTR(p,n) \
  43. if (BAD_IN_MULTISTRUCT_PTR(p,n)) ASSERT_AND_RETURN;
  44. #define WBEM_VALIDATE_OUT_STRUCT_PTR(p) \
  45. if (BAD_OUT_STRUCT_PTR(p)) ASSERT_AND_RETURN;
  46. #define WBEM_VALIDATE_OUT_PTRPTR(p) \
  47. if (NULL == p || IsBadWritePtr(p,sizeof(void*))) ASSERT_AND_RETURN;
  48. #define WBEM_VALIDATE_INTF_PTR(p) \
  49. if (NULL == p || IsBadReadPtr(p,sizeof(void*))) ASSERT_AND_RETURN;
  50. #define WBEM_VALIDATE_IN_STRING_PTR(p) \
  51. if (BAD_IN_STRING_PTR(p)) ASSERT_AND_RETURN;
  52. #define WBEM_VALIDATE_IN_STRING_PTR_OPTIONAL(p) \
  53. if (BAD_IN_STRING_PTR_OPTIONAL(p)) ASSERT_AND_RETURN;