home *** CD-ROM | disk | FTP | other *** search
- /*
- * ReadErr.cpp
- * $Header: /BoundsChecker/Examples/BUGBNCHX/MAINERR/READERR.CPP 3 12/11/96 4:03p Stevea $
- *
- * Description:
- * Read Check error functions.
- *
- * Notes:
- * <implementation notes go here>
- *
- ***********************************************************************
- *
- * Nu-Mega Technologies, Inc.
- * P.O. Box 7780
- * Nashua, NH 03060
- *
- * (c) Copyright 1994, 1995 Nu-Mega Technologies, Inc.
- * ALL RIGHTS RESERVED.
- *
- ***********************************************************************
- *
- **********************************************************************/
- #include "stdafx.h"
- #include "ReadErr.h"
-
- // Read Check - Reading overflows memory
- void Read_ReadOverflowsMem ( )
- {
- _TRY
- {
- char * a = "TEST" ;
- char b [ 20 ] ;
- memcpy ( b , a , sizeof ( b ) ) ;
- }
- _CATCH
- {
- }
- }
-
- struct NotBig
- {
- int x ;
- } ;
-
- struct NotSmall
- {
- double y ;
- } ;
-
- union two_in_one
- {
- struct NotBig a ;
- struct NotSmall b ;
- } ;
-
- void Read_ReadOverflowsStructure ( )
- {
- _TRY
- {
- struct NotBig * var1 ;
- union two_in_one * ptr ;
- double d ;
-
- var1 = (struct NotBig *)malloc ( sizeof ( struct NotBig ) ) ;
- ptr = (union two_in_one *) var1 ;
- d = ptr->b.y ;
- free ( var1 ) ;
- }
- _CATCH
- {
- }
- }
-
- // Read Check - Reading uninitialized memory
- void Read_ReadUninitMem ( )
- {
- _TRY
- {
- LONG * a = (LONG *) malloc ( sizeof ( LONG ) ) ;
- LONG b ;
-
- b = *a ;
- free ( a ) ;
- }
- _CATCH
- {
- }
- }
- // Read Check - String is not NULL terminated within range
- void Read_StringNotNULLTerminated ( )
- {
- _TRY
- {
- char szBuff[ 100 ] ;
- char szData[ 8 ] ;
- strncpy ( szData , "This is a test", sizeof ( szData ) ) ;
- sprintf ( szBuff , "%s\n", szData ) ;
- }
- _CATCH
- {
- }
- }
-