home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 6 / mastvb6.iso / numega / sc501.exe / data1.cab / Examples / WRITEERR.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-11-25  |  2.3 KB  |  110 lines

  1. /*
  2.  * WriteErr.cpp
  3.  * $Header: /BoundsChecker/Examples/BUGBNCHX/MAINERR/WRITEERR.CPP 5     12/13/96 1:51p Stevea $
  4.  *
  5.  * Description:
  6.  *  Write Check error functions.
  7.  *
  8.  * Notes:
  9.  *  <implementation notes go here>
  10.  *
  11.  ***********************************************************************
  12.  *
  13.  * Nu-Mega Technologies, Inc.
  14.  * P.O. Box 7780
  15.  * Nashua, NH 03060
  16.  *
  17.  * (c) Copyright 1994, 1995 Nu-Mega Technologies, Inc.
  18.  * ALL RIGHTS RESERVED.
  19.  *
  20.  ***********************************************************************
  21.  *
  22.  **********************************************************************/
  23. #include "stdafx.h"
  24. #include "WriteErr.h"
  25. #include "BCError.h"
  26.  
  27. // Write Check - Dynamic memory overrun
  28. void Write_DynMemOverrun ( )
  29. {
  30.    // If we are in the middle of doing all errors, we don't want to
  31.    //  do this function!
  32.    if ( TRUE == DoingAllErrors (  ) )
  33.    {
  34.       return ;
  35.    }
  36.  
  37.    _TRY
  38.    {
  39.       TCHAR * szString = new TCHAR [ 10 ] ;
  40.       _tcscpy ( szString , _T ( "012345678910" ) ) ;
  41.       delete [] szString ;
  42.    }
  43.    _CATCH
  44.    {
  45.    }
  46. }
  47. // Write Check - Stack memory overrun
  48. void Write_StackMemOverrun ( )
  49. {
  50.    // If we are in the middle of doing all errors, we don't want to
  51.    //  do this function!
  52.    if ( TRUE == DoingAllErrors (  ) )
  53.    {
  54.       return ;
  55.    }
  56.  
  57.    _TRY
  58.    {
  59.       TCHAR szExtraSpaceOne[ 3 ] ;
  60.       TCHAR szBuff [ 10 ] ;
  61.       TCHAR szSaveOurStack[ 3 ] ;
  62.       szExtraSpaceOne[ 0 ] = _T ( '\0' ) ;
  63.       szSaveOurStack[ 0 ]  = _T ( '\0' ) ;
  64.       _tcscpy ( szBuff , _T ( "01234567891" ) ) ;
  65.    }
  66.    _CATCH
  67.    {
  68.    }
  69. }
  70. // Write Check - Static memory overrun
  71. static TCHAR g_szStaticMem[ 10 ] ;
  72. void Write_StaticMemOverrun ( )
  73. {
  74.    // If we are in the middle of doing all errors, we don't want to
  75.    //  do this function!
  76.    if ( TRUE == DoingAllErrors (  ) )
  77.    {
  78.       return ;
  79.    }
  80.  
  81.    _TRY
  82.    {
  83.       _tcscpy ( g_szStaticMem , _T ( "0123456789" ) ) ;
  84.    }
  85.    _CATCH
  86.    {
  87.    }
  88. }
  89. // Write Check - Writing overflows memory
  90. void Write_WriteOverflowsMem ( )
  91. {
  92.    _TRY
  93.    {
  94.       char szExtraSpace1[ 10 ] ;
  95.       char szBuff[ 9 ] ;
  96.       char szExtraSpace2[ 10 ] ;
  97.  
  98.       // Generate error
  99.       *(szBuff + 12) = 5;
  100.  
  101.       // Get rid of the CL warnings
  102.       szExtraSpace1[ 0 ] = '\0' ;
  103.       szExtraSpace2[ 0 ] = '\0' ;
  104.  
  105.    }
  106.    _CATCH
  107.    {
  108.    }
  109. }
  110.