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

  1. /*
  2.  * ReadErr.cpp
  3.  * $Header: /BoundsChecker/Examples/BUGBNCHX/MAINERR/READERR.CPP 3     12/11/96 4:03p Stevea $
  4.  *
  5.  * Description:
  6.  *  Read 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 "ReadErr.h"
  25.  
  26. // Read Check - Reading overflows memory
  27. void Read_ReadOverflowsMem ( )
  28. {
  29.    _TRY
  30.    {
  31.       char * a = "TEST" ;
  32.       char b [ 20 ] ;
  33.       memcpy ( b , a , sizeof ( b ) ) ;
  34.    }
  35.    _CATCH
  36.    {
  37.    }
  38. }
  39.  
  40. struct NotBig
  41. {
  42.    int x ;
  43. } ;
  44.  
  45. struct NotSmall
  46. {
  47.    double y ;
  48. } ;
  49.  
  50. union two_in_one
  51. {
  52.    struct NotBig a ;
  53.    struct NotSmall   b ;
  54. } ;
  55.  
  56. void Read_ReadOverflowsStructure ( )
  57. {
  58.    _TRY
  59.    {
  60.       struct NotBig *     var1 ;
  61.       union two_in_one * ptr  ;
  62.       double             d    ;
  63.  
  64.       var1 = (struct NotBig *)malloc ( sizeof ( struct NotBig ) ) ;
  65.       ptr = (union two_in_one *) var1 ;
  66.       d = ptr->b.y ;
  67.       free ( var1 ) ;
  68.    }
  69.    _CATCH
  70.    {
  71.    }
  72. }
  73.  
  74. // Read Check - Reading uninitialized memory
  75. void Read_ReadUninitMem ( )
  76. {
  77.    _TRY
  78.    {
  79.       LONG * a = (LONG *) malloc ( sizeof ( LONG ) ) ;
  80.       LONG   b ;
  81.  
  82.       b = *a ;
  83.       free ( a ) ;
  84.    }
  85.    _CATCH
  86.    {
  87.    }
  88. }
  89. // Read Check - String is not NULL terminated within range
  90. void Read_StringNotNULLTerminated ( )
  91. {
  92.    _TRY
  93.    {
  94.       char szBuff[ 100 ] ;
  95.       char szData[ 8 ]   ;
  96.            strncpy ( szData , "This is a test", sizeof ( szData ) ) ;
  97.            sprintf ( szBuff , "%s\n", szData ) ;
  98.    }
  99.    _CATCH
  100.    {
  101.    }
  102. }
  103.