Team Fortress 2 Source Code as on 22/4/2020
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.

84 lines
3.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. #ifndef ANALYSIS_ANNOTATIONS_H
  3. #define ANALYSIS_ANNOTATIONS_H
  4. #if _MSC_VER >= 1600 // VS 2010 and above.
  5. //-----------------------------------------------------------------------------
  6. // Upgrading important helpful warnings to errors
  7. //-----------------------------------------------------------------------------
  8. #pragma warning(error : 4789 ) // warning C4789: destination of memory copy is too small
  9. // Suppress some code analysis warnings
  10. #ifdef _PREFAST_
  11. // Include the annotation header file.
  12. #include <sal.h>
  13. // For temporarily suppressing warnings -- the warnings are suppressed for the next source line.
  14. #define ANALYZE_SUPPRESS(wnum) __pragma(warning(suppress: wnum))
  15. #define ANALYZE_SUPPRESS2(wnum1, wnum2) __pragma(warning(supress: wnum1 wnum2))
  16. #define ANALYZE_SUPPRESS3(wnum1, wnum2, wnum3) __pragma(warning(suppress: wnum1 wnum2 wnum3))
  17. #define ANALYZE_SUPPRESS4(wnum1, wnum2, wnum3, wnum4) __pragma(warning(suppress: wnum1 wnum2 wnum3 wnum4))
  18. // Tag all printf style format strings with this
  19. #define PRINTF_FORMAT_STRING _Printf_format_string_
  20. #define SCANF_FORMAT_STRING _Scanf_format_string_impl_
  21. // Various macros for specifying the capacity of the buffer pointed
  22. // to by a function parameter. Variations include in/out/inout,
  23. // CAP (elements) versus BYTECAP (bytes), and null termination or
  24. // not (_Z).
  25. #define IN_Z _In_z_
  26. #define IN_CAP(x) _In_count_(x)
  27. #define IN_BYTECAP(x) _In_bytecount_(x)
  28. #define OUT_Z_CAP(x) _Out_z_cap_(x)
  29. #define OUT_CAP(x) _Out_cap_(x)
  30. #define OUT_CAP_C(x) _Out_cap_c_(x) // Output buffer with specified *constant* capacity in elements
  31. #define OUT_BYTECAP(x) _Out_bytecap_(x)
  32. #define OUT_Z_BYTECAP(x) _Out_z_bytecap_(x)
  33. #define INOUT_BYTECAP(x) _Inout_bytecap_(x)
  34. #define INOUT_Z_CAP(x) _Inout_z_cap_(x)
  35. #define INOUT_Z_BYTECAP(x) _Inout_z_bytecap_(x)
  36. // These macros are use for annotating array reference parameters, typically used in functions
  37. // such as V_strcpy_safe. Because they are array references the capacity is already known.
  38. #if _MSC_VER >= 1700
  39. #define IN_Z_ARRAY _Pre_z_
  40. #define OUT_Z_ARRAY _Post_z_
  41. #define INOUT_Z_ARRAY _Prepost_z_
  42. #else
  43. #define IN_Z_ARRAY _Deref_pre_z_
  44. #define OUT_Z_ARRAY _Deref_post_z_
  45. #define INOUT_Z_ARRAY _Deref_prepost_z_
  46. #endif // _MSC_VER >= 1700
  47. // Used for annotating functions to describe their return types.
  48. #define MUST_CHECK_RETURN _Check_return_
  49. // Use the macros above to annotate string functions that fill buffers as shown here,
  50. // in order to give VS's /analyze more opportunities to find bugs.
  51. // void V_wcsncpy( OUT_Z_BYTECAP(maxLenInBytes) wchar_t *pDest, wchar_t const *pSrc, int maxLenInBytes );
  52. // int V_snwprintf( OUT_Z_CAP(maxLenInCharacters) wchar_t *pDest, int maxLenInCharacters, PRINTF_FORMAT_STRING const wchar_t *pFormat, ... );
  53. #endif // _PREFAST_
  54. #endif // _MSC_VER >= 1600 // VS 2010 and above.
  55. #ifndef ANALYZE_SUPPRESS
  56. #define ANALYZE_SUPPRESS(wnum)
  57. #define ANALYZE_SUPPRESS2(wnum1, wnum2)
  58. #define ANALYZE_SUPPRESS3(wnum1, wnum2, wnum3)
  59. #define ANALYZE_SUPPRESS4(wnum1, wnum2, wnum3, wnum4)
  60. #define PRINTF_FORMAT_STRING
  61. #define SCANF_FORMAT_STRING
  62. #define IN_Z
  63. #define IN_CAP(x)
  64. #define IN_BYTECAP(x)
  65. #define OUT_Z_CAP(x)
  66. #define OUT_CAP(x)
  67. #define OUT_CAP_C(x)
  68. #define OUT_BYTECAP(x)
  69. #define OUT_Z_BYTECAP(x)
  70. #define INOUT_BYTECAP(x)
  71. #define INOUT_Z_CAP(x)
  72. #define INOUT_Z_BYTECAP(x)
  73. #define OUT_Z_ARRAY
  74. #define INOUT_Z_ARRAY
  75. #define MUST_CHECK_RETURN
  76. #endif
  77. #endif // ANALYSIS_ANNOTATIONS_H