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.

122 lines
3.9 KiB

  1. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Microsoft WMI OLE DB Provider
  4. // (C) Copyright 1999 Microsoft Corporation. All Rights Reserved.
  5. //
  6. // Simple Assertion Routines
  7. //
  8. ///////////////////////////////////////////////////////////////////////////////////////////////////
  9. #include "headers.h"
  10. #include <time.h>
  11. #include "asserts.h"
  12. //=======================================================================================
  13. // only compile for debug!
  14. //=======================================================================================
  15. #ifdef DEBUG
  16. /////////////////////////////////////////////////////////////////////////////////////////
  17. //
  18. // Variable argument formatter and Dump routine for messages
  19. //
  20. /////////////////////////////////////////////////////////////////////////////////////////
  21. void OLEDB_Trace( const char *format, // IN Format String
  22. ... // IN Variable Arg List
  23. )
  24. {
  25. char buff[300 ];
  26. int cBytesWritten;
  27. va_list argptr;
  28. //====================================================================================
  29. // If this overflows, it will wipe out the return stack. However, we have a wonderful
  30. // version that ensures no overwrite. Nice because we can't do anything about errors
  31. // here.
  32. //====================================================================================
  33. va_start( argptr, format );
  34. cBytesWritten = _vsnprintf( buff, sizeof( buff ), format, argptr );
  35. va_end( argptr );
  36. //====================================================================================
  37. // assert would report overflow first, recursively, but don't bother.
  38. // Would be OK, since this assert could be proven not to overflow temp buffer in assert.
  39. // assert( cBytesWritten < sizeof(buff) );
  40. //====================================================================================
  41. OutputDebugStringA( buff );
  42. }
  43. /////////////////////////////////////////////////////////////////////////////////////////
  44. //
  45. // This an internal assertion routine that dumps more information
  46. // than the normal assertion routines..
  47. //
  48. /////////////////////////////////////////////////////////////////////////////////////////
  49. void OLEDB_Assert( LPSTR expression, // IN Expression to assert on
  50. LPSTR filename, // IN Filname where assertion occurred
  51. long linenum // IN Line number where assertion occurred
  52. )
  53. {
  54. char szbuff[350 ];
  55. int cBytesWritten;
  56. volatile int fAbort;
  57. //====================================================================================
  58. // If this overflows, it will wipe out the return stack.
  59. // However, we have a wonderful version that ensures no overwrite.
  60. // Good thing, because we can't do much about overflows here anyway.
  61. // (However, use of "%.nns" works well.)
  62. //====================================================================================
  63. cBytesWritten = _snprintf( szbuff, sizeof( szbuff ),
  64. "Assertion error!\n File '%.50s', line '%ld'\n Expression '%.200s'\n",
  65. filename, linenum, expression );
  66. TRACE( szbuff );
  67. //====================================================================================
  68. // We're a DLL (therefore Windows), so may not have an output stream we can write to.
  69. //====================================================================================
  70. ::MessageBoxA(
  71. NULL, // HWND, which we don't have
  72. szbuff, // Text
  73. "Assertion Error", // Title
  74. MB_SYSTEMMODAL | MB_ICONHAND | MB_OK );
  75. //====================================================================================
  76. // Break and let the user get a crack at it. Set fAbort=0 to continue merrily along.
  77. //====================================================================================
  78. fAbort = 1;
  79. if (fAbort){
  80. abort(); // Raises SIGABRT
  81. }
  82. }
  83. #endif