Counter Strike : Global Offensive Source Code
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.

116 lines
7.0 KiB

  1. #ifndef ANALYSIS_ANNOTATIONS_H
  2. #define ANALYSIS_ANNOTATIONS_H
  3. #if _MSC_VER >= 1600 // VS 2010 and above.
  4. //-----------------------------------------------------------------------------
  5. // Upgrading important helpful warnings to errors
  6. //-----------------------------------------------------------------------------
  7. #pragma warning(error : 4789 ) // warning C4789: destination of memory copy is too small
  8. // Suppress some code analysis warnings
  9. #ifdef _PREFAST_
  10. // Include the annotation header file.
  11. #include <sal.h>
  12. // /Analyze warnings can only be suppressed when using a compiler that supports them, which VS 2010
  13. // Professional does not.
  14. // We don't care about these warnings because they are bugs that can only occur during resource
  15. // exhaustion or other unexpected API failure, which we are nowhere near being able to handle.
  16. #pragma warning(disable : 6308) // warning C6308: 'realloc' might return null pointer: assigning null pointer to 's_ppTestCases', which is passed as an argument to 'realloc', will cause the original memory block to be leaked
  17. #pragma warning(disable : 6255) // warning C6255: _alloca indicates failure by raising a stack overflow exception. Consider using _malloca instead
  18. #pragma warning(disable : 6387) // warning C6387: 'argument 1' might be '0': this does not adhere to the specification for the function 'GetProcAddress'
  19. #pragma warning(disable : 6309) // warning C6309: Argument '1' is null: this does not adhere to function specification of 'GetProcAddress'
  20. #pragma warning(disable : 6011) // warning C6011: Dereferencing NULL pointer 'm_ppTestCases'
  21. #pragma warning(disable : 6211) // warning C6211: Leaking memory 'newKeyValue' due to an exception. Consider using a local catch block to clean up memory
  22. #pragma warning(disable : 6031) // warning C6031: Return value ignored: '_getcwd'
  23. // These warnings are because /analyze doesn't like our use of constants, especially things like IsPC()
  24. #pragma warning(disable : 6326) // warning C6326: Potential comparison of a constant with another constant
  25. #pragma warning(disable : 6239) // warning C6239: (<non-zero constant> && <expression>) always evaluates to the result of <expression>. Did you intend to use the bitwise-and operator?
  26. #pragma warning(disable : 6285) // warning C6285: (<non-zero constant> || <non-zero constant>) is always a non-zero constant. Did you intend to use the bitwise-and operator?
  27. #pragma warning(disable : 6237) // warning C6237: (<zero> && <expression>) is always zero. <expression> is never evaluated and might have side effects
  28. #pragma warning(disable : 6235) // warning C6235: (<non-zero constant> || <expression>) is always a non-zero constant
  29. #pragma warning(disable : 6240) // warning C6240: (<expression> && <non-zero constant>) always evaluates to the result of <expression>. Did you intend to use the bitwise-and operator?
  30. // These warnings aren't really important:
  31. #pragma warning(disable : 6323) // warning C6323: Use of arithmetic operator on Boolean type(s)
  32. // Miscellaneous other /analyze warnings. We should consider fixing these at some point.
  33. //#pragma warning(disable : 6204) // warning C6204: Possible buffer overrun in call to 'memcpy': use of unchecked parameter 'src'
  34. //#pragma warning(disable : 6262) // warning C6262: Function uses '16464' bytes of stack: exceeds /analyze:stacksize'16384'. Consider moving some data to heap
  35. // This is a serious warning. Don't suppress it.
  36. //#pragma warning(disable : 6263) // warning C6263: Using _alloca in a loop: this can quickly overflow stack
  37. // 6328 is also used for passing __int64 to printf when int is expected so we can't suppress it.
  38. //#pragma warning(disable : 6328) // warning C6328: 'char' passed as parameter '1' when 'unsigned char' is required in call to 'V_isdigit'
  39. // /analyze doesn't like GCOMPILER_ASSERT's implementation of compile-time asserts
  40. #pragma warning(disable : 6326) // warning C6326: Potential comparison of a constant with another constant
  41. #pragma warning(disable : 6335) // warning C6335: Leaking process information handle 'pi.hThread'
  42. #pragma warning(disable : 6320) // warning C6320: Exception-filter expression is the constant EXCEPTION_EXECUTE_HANDLER. This might mask exceptions that were not intended to be handled
  43. #pragma warning(disable : 6250) // warning C6250: Calling 'VirtualFree' without the MEM_RELEASE flag might free memory but not address descriptors (VADs). This causes address space leaks
  44. #pragma warning(disable : 6384) // ientity2_class_h_schema_gen.cpp(76): warning C6384: Dividing sizeof a pointer by another value
  45. // For temporarily suppressing warnings -- the warnings are suppressed for the next source line.
  46. #define ANALYZE_SUPPRESS(wnum) __pragma(warning(suppress: wnum))
  47. #define ANALYZE_SUPPRESS2(wnum1, wnum2) __pragma(warning(supress: wnum1 wnum2))
  48. #define ANALYZE_SUPPRESS3(wnum1, wnum2, wnum3) __pragma(warning(suppress: wnum1 wnum2 wnum3))
  49. #define ANALYZE_SUPPRESS4(wnum1, wnum2, wnum3, wnum4) __pragma(warning(suppress: wnum1 wnum2 wnum3 wnum4))
  50. // Tag all printf style format strings with this
  51. #define PRINTF_FORMAT_STRING _Printf_format_string_
  52. #define SCANF_FORMAT_STRING _Scanf_format_string_impl_
  53. // Various macros for specifying the capacity of the buffer pointed
  54. // to by a function parameter. Variations include in/out/inout,
  55. // CAP (elements) versus BYTECAP (bytes), and null termination or
  56. // not (_Z).
  57. #define IN_Z _In_z_
  58. #define IN_CAP(x) _In_count_(x)
  59. #define IN_BYTECAP(x) _In_bytecount_(x)
  60. #define OUT_Z_CAP(x) _Out_z_cap_(x)
  61. #define OUT_CAP(x) _Out_cap_(x)
  62. #define OUT_BYTECAP(x) _Out_bytecap_(x)
  63. #define OUT_Z_BYTECAP(x) _Out_z_bytecap_(x)
  64. #define INOUT_BYTECAP(x) _Inout_bytecap_(x)
  65. #define INOUT_Z_CAP(x) _Inout_z_cap_(x)
  66. #define INOUT_Z_BYTECAP(x) _Inout_z_bytecap_(x)
  67. // These macros are use for annotating array reference parameters, typically used in functions
  68. // such as V_strcpy_safe. Because they are array references the capacity is already known.
  69. #if _MSC_VER >= 1700
  70. #define IN_Z_ARRAY _Pre_z_
  71. #define OUT_Z_ARRAY _Post_z_
  72. #define INOUT_Z_ARRAY _Prepost_z_
  73. #else
  74. #define IN_Z_ARRAY _Deref_pre_z_
  75. #define OUT_Z_ARRAY _Deref_post_z_
  76. #define INOUT_Z_ARRAY _Deref_prepost_z_
  77. #endif // _MSC_VER >= 1700
  78. // Use the macros above to annotate string functions that fill buffers as shown here,
  79. // in order to give VS's /analyze more opportunities to find bugs.
  80. // void V_wcsncpy( OUT_Z_BYTECAP(maxLenInBytes) wchar_t *pDest, wchar_t const *pSrc, int maxLenInBytes );
  81. // int V_snwprintf( OUT_Z_CAP(maxLenInCharacters) wchar_t *pDest, int maxLenInCharacters, PRINTF_FORMAT_STRING const wchar_t *pFormat, ... );
  82. #endif // _PREFAST_
  83. #endif // _MSC_VER >= 1600 // VS 2010 and above.
  84. #ifndef ANALYZE_SUPPRESS
  85. #define ANALYZE_SUPPRESS(wnum)
  86. #define ANALYZE_SUPPRESS2(wnum1, wnum2)
  87. #define ANALYZE_SUPPRESS3(wnum1, wnum2, wnum3)
  88. #define ANALYZE_SUPPRESS4(wnum1, wnum2, wnum3, wnum4)
  89. #define PRINTF_FORMAT_STRING
  90. #define SCANF_FORMAT_STRING
  91. #define IN_Z
  92. #define IN_CAP(x)
  93. #define IN_BYTECAP(x)
  94. #define OUT_Z_CAP(x)
  95. #define OUT_CAP(x)
  96. #define OUT_BYTECAP(x)
  97. #define OUT_Z_BYTECAP(x)
  98. #define INOUT_BYTECAP(x)
  99. #define INOUT_Z_CAP(x)
  100. #define INOUT_Z_BYTECAP(x)
  101. #define OUT_Z_ARRAY
  102. #define INOUT_Z_ARRAY
  103. #endif
  104. #endif // ANALYSIS_ANNOTATIONS_H