home *** CD-ROM | disk | FTP | other *** search
- /*
- * BCError.cpp
- * $Header: /BoundsChecker/Examples/BUGBNCHX/MAINERR/BCERROR.CPP 20 5/08/97 10:19a Bob $
- *
- * Description:
- * Holds the data structures to fill the Tree Control with. Also has
- * the random error function.
- *
- * 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 <time.h>
- #include "BCError.h"
-
- #include "BCTree.h"
-
- // The function prototypes for all the functions that actually cause
- // errors. How cool, I get to actually write bugs -- purposely, for
- // a change!
- #include "OLEErr.h"
- #include "APIErr.h"
- #include "CPPErr.h"
- #include "LeakErr.h"
- #include "PtrErr.h"
- #include "ReadErr.h"
- #include "WriteErr.h"
-
- ////////////////////////////////////////////////////////////////////////
- // Constants that give the sizes of the data structure arrays.
- ////////////////////////////////////////////////////////////////////////
- // The number of root objects. (0 level objects)
- const constNumRootObjects = 9 ;
- // The maximum number of different errors under a particular root
- // object. (1st level objects)
- const constMaxErrsPerCatagory = 24 ;
- // The number of leaf nodes, and consequently, the number of error
- // functions.
- const constMaxNumErrorFuncs = 82 ;
- // The maximum possible error functions under a first level object.
- const constMaxErrsPerType = 4 ;
- // The number of times we will randomly execute a function.
- const constNumRandomFuncs = 5 ;
-
- #ifdef BCBVER
- const TCHAR szModName [] = _T ( "bcberr.bug" ) ;
- #else
- const TCHAR szModName [] = _T ( "mainerr.bug" ) ;
- #endif
-
- const constMaxLParam = 1024 ;
-
- ////////////////////////////////////////////////////////////////////////
- int g_nLParam ;
- LParamInfo* g_lParamArray[ constMaxLParam ] ;
- ////////////////////////////////////////////////////////////////////////
- // The array of root objects, these are the error categories.
- ////////////////////////////////////////////////////////////////////////
-
- ErrorCatagory g_RootObjects[ constNumRootObjects ] =
- {
- {
- IDS_APIANDOLECHECK ,
- IDS_APIANDOLECHECKDESC
- } ,
- {
- IDS_MEMORYCHECK ,
- IDS_MEMORYCHECKDESC
- } ,
- {
- IDS_POINTERANDLEAKCHECK ,
- IDS_POINTERANDLEAKCHECKDESC
- } ,
- // Always leave the NULL to indicate the end.
- {
- NULL ,
- NULL
- }
- } ;
-
- ////////////////////////////////////////////////////////////////////////
- // The array of first level objects. These are the individual errors
- // or error types. This is a 2 dimentional array that has a string id
- // in the first position and a TRUE/FALSE flag in the second position.
- // The string id is the id of the string that will be displayed in the
- // tree control. The boolean flag is used to indicate wether or not
- // the error can be caught without compile time instrumentation, CTI.
- ////////////////////////////////////////////////////////////////////////
-
- ErrorType g_ArrayOfTypes[constNumRootObjects][constMaxErrsPerCatagory] =
- {
- ///////////////////////////////////////////////////////////////////////////////
- // API AND OLE CHECK TYPES
- {
- {// Questionable use of thread
- IDS_QUESTIONALBEUSEOTHREAD ,
- TRUE ,
- } ,
- {// API failure: Windows function failed
- IDS_APIFAILWINFUNCFAIL ,
- TRUE ,
- } ,
- {// API failure: function not implemented
- IDS_APIFAILWINFUNCNOTIMP ,
- TRUE ,
- } ,
- {// Interface method failure
- IDS_OLEFAILINTFUNCFAIL ,
- TRUE ,
- } ,
- {// Invalid argument
- IDS_INVALIDARGGENERAL ,
- TRUE ,
- } ,
- {// Invalid argument - At least one format specifier is illegal
- IDS_INVALIDARGBADFMTSPECIFIER ,
- TRUE ,
- } ,
- {// Invalid argument - bad destination pointer
- IDS_INVALIDARGBADDESTPTR ,
- TRUE ,
- } ,
- {// Invalid argument - bad handle
- IDS_INVALIDARGBADHANDLE ,
- TRUE ,
- } ,
- {// Invalid argument - bad source pointer
- IDS_INVALIDARGBADSRCPTR ,
- TRUE ,
- } ,
- {// Invalid argument - conflicting combination of flags
- IDS_INVALIDARGCONFLICT ,
- TRUE ,
- } ,
- {// Invalid argument - format string not followed by valid arguments
- IDS_INVALIDARGFMTINVALIDARG ,
- TRUE ,
- } ,
- {// Invalid argument: Invalid pointer to format string
- IDS_INVALIDARGBADFMTSTR ,
- TRUE ,
- } ,
- {// Invalid argument: Not enough arguments for this format string
- IDS_INVALUDARGINSUFFPARAMS ,
- TRUE ,
- } ,
- {// Invalid argument: Out of range
- IDS_INVALIDARGOUTORANGE ,
- TRUE ,
- } ,
- {// Invalid argument: Structure size field is not initialized
- IDS_INVALIDARGSTRUCTURE ,
- TRUE ,
- } ,
- {// Invalid argument - Too many arguments for this format string
- IDS_INVALIDARGTOOMANYPARAMS ,
- TRUE ,
- } ,
- {// Invalid argument - Undefined or illegal flags
- IDS_INVALIDARGUNDEFINED ,
- TRUE ,
- } ,
- {// Invalid Interface method argument
- IDS_OLEINVALIDARGGENERAL ,
- TRUE ,
- } ,
- {// Invalid Interface method argument: conflicting combination of flags
- IDS_OLEINVALIDARGCONFFLAGS ,
- TRUE ,
- } ,
- {// Invalid Interface method argument: Out of range
- IDS_OLEINVALIDARGBADRANGE ,
- TRUE ,
- } ,
- {// Invalid Interface method argument: Structure size field is not initialized
- IDS_OLEINVALIDARGSTRCTUNINT ,
- TRUE ,
- } ,
- {// Invalid Interface method argument: Undefined or illegal flags
- IDS_OLEINVALIDARGUNDEFFLAGS ,
- TRUE ,
- } ,
- { NULL }
- } ,
-
- ///////////////////////////////////////////////////////////////////////////////
- // MEMORY CHECK TYPES
- {
- {// Dynamic memory overrun
- IDS_DYNMEMOVERRUN ,
- TRUE ,
- } ,
- {// Freed handle is still locked
- IDS_INVALIDARGFREEDHANDLELOCK ,
- TRUE ,
- } ,
- {// Handle is already unlocked
- IDS_INVALIDARGHANDLEUNLOCKED ,
- TRUE ,
- } ,
- {// Memory allocation conflict
- IDS_MEMALLOCCONFLICT ,
- TRUE ,
- } ,
- {// Pointer references unlocked memory block
- IDS_PTRREFSUNLOCKEDBLOCK ,
- TRUE ,
- } ,
- #ifndef BCBVER
- {// Reading overflows memory
- IDS_READOVERFLOWSMEM ,
- FALSE ,
- } ,
- {// Reading uninitialized memory
- IDS_READUNINITMEM ,
- FALSE ,
- } ,
- #endif
- {// Stack memory overrun
- IDS_STACKMEMOVERRUN ,
- TRUE ,
- } ,
- {// Static memory overrun
- IDS_STATICMEMOVERRUN ,
- TRUE ,
- } ,
- #ifndef BCBVER
- {// Writing overflows memory
- IDS_WRITINGOVERFLOWSMEM ,
- FALSE ,
- } ,
- #endif
- { NULL }
- } ,
-
- ///////////////////////////////////////////////////////////////////////////////
- // POINTER AND LEAK CHECK TYPES
- {
- #ifndef BCBVER
- {// Array index out of range
- IDS_ARRAYPARAMEXCEEDSRANGE ,
- FALSE ,
- } ,
- {// Assigning pointer out of range
- IDS_ASSIGNINGPTROUTOFRANGE ,
- FALSE ,
- } ,
- {// Expression uses unrelated pointers
- IDS_EXPRUSESUNRELPTR ,
- FALSE ,
- } ,
- {// Expression uses dangling pointer
- IDS_EXPRTRUSESDANGLEPTR ,
- FALSE ,
- } ,
- {// Function pointer is not a function
- IDS_FNPTRNOTAFN ,
- FALSE ,
- } ,
- #endif
- {// Interface leak
- IDS_OLEINTLEAK ,
- TRUE ,
- } ,
- {// Memory leak
- IDS_MEMLEAKGENERAL ,
- TRUE ,
- } ,
- #ifndef BCBVER
- {// Memory leaked due to free
- IDS_MEMLEAKTOFREE ,
- FALSE ,
- } ,
- {// Memory leaked due to reassignment
- IDS_MEMLEAKREASSIGN ,
- FALSE ,
- } ,
- {// Memory leaked leaving scope
- IDS_MEMLEAKLEAVESCOPE ,
- FALSE ,
- } ,
- #endif
- {// Resource leak
- IDS_RESOURCELEAK ,
- TRUE ,
- } ,
- #ifndef BCBVER
- {// Returning pointer to local variable
- IDS_RETURNINGPTRTOLOCALVAR,
- FALSE ,
- } ,
- #endif
- {// Unallocated pointer
- IDS_UNALLOCATEDPTR ,
- TRUE ,
- } ,
- { NULL }
- }
- } ;
-
-
- ////////////////////////////////////////////////////////////////////////
- // The array of leaf nodes, or occurrences. This is where the pointers
- // to the error functions are stored.
- ////////////////////////////////////////////////////////////////////////
-
- // The array that holds all the error occurrences.
- ErrorOccurance g_aOccurArray[constMaxNumErrorFuncs][constMaxErrsPerType]=
- {
- ///////////////////////////////////////////////////////////////////////////////
- // API AND OLE ERRORS
-
- {// Questionable use of thread
- {
- IDS_QUESTIONTHREADINST ,
- IDS_QUESTIONTHREADDESC ,
- API_QuestionableUseOfThread
- } ,
- { NULL } ,
- { NULL } ,
- { NULL }
- } ,
- {// API failure: Windows function failed
- {
- IDS_APIFAILLOADBITMAPINST ,
- IDS_APIFAILLOADBITMAPDESC ,
- API_Failure_LoadBitmap ,
- } ,
- #ifndef BCBVER
- {
- IDS_APIFAILMALLOCINST ,
- IDS_APIFAILMALLOCDESC ,
- API_Failure_Malloc ,
- } ,
- #else
- { NULL },
- #endif
- { NULL } ,
- { NULL } ,
- } ,
- {// API failure: function not implemented
- {
- IDS_APIFAILNOTIMPINSTNT ,
- IDS_APIFAILNOTIMPDESCNT ,
- API_Failure_PaintDesktop ,
- } ,
- {
- IDS_APIFAILNOTIMPINST95 ,
- IDS_APIFAILNOTIMPDESC95 ,
- API_Failure_HeapValidate ,
- } ,
- { NULL } ,
- { NULL } ,
- } ,
- {// Interface method failure
- {
- IDS_OLEINTFMETHODFAIL ,
- IDS_OLEINTFMETHODFAILDESC ,
- OLE_IntfFail_QueryInterface ,
- } ,
- { NULL } ,
- { NULL } ,
- { NULL } ,
- } ,
- {// Invalid argument
- {
- IDS_INVARGGENHDCINST ,
- IDS_INVARGGENHDCDESC ,
- API_General_HDC
- } ,
- {
- IDS_INVARGGENHMENUINST ,
- IDS_INVARGGENHMENUDESC ,
- API_General_HMENU
- } ,
- { NULL } ,
- { NULL }
- } ,
- {// Invalid argument - At least one format specifier is illegal
- {
- IDS_ILLEGALFORMATSPECINST ,
- IDS_ILLEGALFORMATSPECDESC ,
- API_IllegalFormatSpec ,
- } ,
- { NULL } ,
- { NULL } ,
- { NULL } ,
- } ,
- {// Invalid argument - bad destination pointer
- {
- IDS_BADDESTPTRINST ,
- IDS_BADDESTPTRDESC ,
- API_BadDestPtr ,
- } ,
- { NULL } ,
- { NULL } ,
- { NULL } ,
- } ,
- {// Invalid argument - bad handle
- {
- IDS_BADHANDLEFREEINST ,
- IDS_BADHANDLEFREEDESC ,
- API_BadHandleFree ,
- } ,
- {
- IDS_BADHANDLELFREEINST ,
- IDS_BADHANDLELFREEDESC ,
- API_BadHandleLocalFree ,
- } ,
- #ifndef BCBVER
- {
- IDS_BADHANDLEREMALLOCINST ,
- IDS_BADHANDLEREMALLOCDESC ,
- API_BadHandleRealloc ,
- } ,
- #else
- { NULL } ,
- #endif
- { NULL } ,
- } ,
- {// Invalid argument - bad source pointer
- {
- IDS_BADSOURCEPTRINST ,
- IDS_BADSOURCEPTRDESC ,
- API_BadSourcePtr ,
- } ,
- { NULL } ,
- { NULL } ,
- { NULL } ,
- } ,
- {// Invalid argument - conflicting combination of flags
- {
- IDS_INVALIDARGGETSTRINGTYPEINST ,
- IDS_INVALIDARGGETSTRINGTYPEDESC ,
- API_ConflictFlags_GetStringTypeEx
- } ,
- {
- IDS_INVALIDARGVIRTUALFREEINST ,
- IDS_INVALIDARGVIRTUALFREEDESC ,
- API_ConflictFlags_VirtualFree
- } ,
- { NULL } ,
- { NULL }
- } ,
- {// Invalid argument - format string not followed by valid arguments
- {
- IDS_FMTSTRNOTFOLLOWEDINST ,
- IDS_FMTSTRNOTFOLLOWEDDESC ,
- API_FmtStrNotFollowed ,
- } ,
- { NULL } ,
- { NULL } ,
- { NULL } ,
- } ,
- {// Invalid argument: Invalid pointer to format string
- {
- IDS_INVPTRTOFMTSTRINST ,
- IDS_INVPTRTOFMTSTRDESC ,
- API_InvPtrToFmtString ,
- } ,
- { NULL } ,
- { NULL } ,
- { NULL } ,
- } ,
- {// Invalid argument: Not enough arguments for this format string
- {
- IDS_NOTENUFARGSFORFMTINST ,
- IDS_NOTENUFARGSFORFMTDESC ,
- API_NotEnufArgsForFmtStr ,
- } ,
- { NULL } ,
- { NULL } ,
- { NULL } ,
- } ,
- {// Invalid argument: Out of range
- {
- IDS_INVALIDARGRANGEINST ,
- IDS_INVALIDARGRANGEDESC ,
- API_ArgOutOfRange_GetKeyState
- } ,
- {
- IDS_INVALIDARGCREATEFONTINST ,
- IDS_INVALIDARGCREATEFONTDESC ,
- API_ArgOutOfRange_CreateFont
- } ,
- {
- IDS_INVARGARGCREATEPIPEINST ,
- IDS_INVARGARGCREATEPIPEDESC ,
- API_ArgOutOfRange_CreateFile
- } ,
- { NULL }
- } ,
- {// Invalid argument: Structure size field is not initialized
- {
- IDS_STRCTSIZEFIELDUNINITINST ,
- IDS_STRCTSIZEFIELDUNINITDESC ,
- API_StructSizeZero ,
- } ,
- { NULL } ,
- { NULL } ,
- { NULL } ,
- } ,
- {// Invalid argument - Too many arguments for this format string
- {
- IDS_TOOMANYARGSFORFMTSTRINST ,
- IDS_TOOMANYARGSFORFMTSTRDESC ,
- API_TooManyArgsForFmtStr ,
- } ,
- { NULL } ,
- { NULL } ,
- { NULL } ,
- } ,
- {// Invalid argument - Undefined or illegal flags
- {
- IDS_INVALIDARGAPPENDMENUINST ,
- IDS_INVALIDARGAPPENDMENUDESC ,
- API_IllegalFlags_AppendMenu
- } ,
- {
- IDS_INVALIDARGFOLDSTRINGINST ,
- IDS_INVALIDARGFOLDSTRINGDESC ,
- API_IllegalFlags_FoldString
- } ,
- { NULL },
- { NULL },
- } ,
- {// Invalid Interface method argument
- {
- IDS_OLEINVARGGEN ,
- IDS_OLEINVARGGENDESC ,
- OLE_IntfArg_General_QueryGetData ,
- } ,
- { NULL } ,
- { NULL } ,
- { NULL } ,
- } ,
- {// Invalid Interface method argument: conflicting combination of flags
- {
- IDS_OLEINVALIDFLAGCOMBO ,
- IDS_OLEINVALIDFLAGCOMBODESC ,
- OLE_IntfArg_BadComboFlag_SetAdvise ,
- } ,
- { NULL } ,
- { NULL } ,
- { NULL } ,
- } ,
- {// Invalid Interface method argument: Out of range
- {
- IDS_OLEINVARGOUTRANGE ,
- IDS_OLEINVARGOUTRANGEDESC ,
- OLE_IntfArg_BadRange_Draw ,
- } ,
- { NULL } ,
- { NULL } ,
- { NULL } ,
- } ,
- {// Invalid Interface method argument: Structure size field is not initialized
- {
- IDS_OLESTRCTSIZFLD ,
- IDS_OLESTRCTSIZFLDDESC ,
- OLE_IntfArg_StructSize_Draw ,
- } ,
- { NULL } ,
- { NULL } ,
- { NULL } ,
- } ,
- {// Invalid Interface method argument: Undefined or illegal flags
- {
- IDS_OLEINVALIDFLAG ,
- IDS_OLEINVALIDFLAGDESC ,
- OLE_IntfArg_InvalidFlag_SetAdvise ,
- } ,
- { NULL } ,
- { NULL } ,
- { NULL } ,
- } ,
-
- ///////////////////////////////////////////////////////////////////////////////
- // MEMORY ERRORS
-
- {// Dynamic memory overrun
- {
- IDS_DYNMEMOVERRUNINST ,
- IDS_DYNMEMOVERRUNDESC ,
- Write_DynMemOverrun ,
- } ,
- { NULL } ,
- { NULL } ,
- { NULL } ,
- } ,
- {// Freed handle is still locked
- {
- IDS_FREEDHANDLELOCKEDINST ,
- IDS_FREEDHANDLELOCKEDDESC ,
- API_FreedHandleStillLocked ,
- } ,
- { NULL } ,
- { NULL } ,
- { NULL } ,
- } ,
- {// Handle is already unlocked
- {
- IDS_HANDLEALREADYUNLOCKEDINST ,
- IDS_HANDLEALREADYUNLOCKEDDESC ,
- API_HandleAlreadyUnlocked ,
- } ,
- { NULL } ,
- { NULL } ,
- { NULL } ,
- } ,
- {// Memory allocation conflict
- {
- IDS_MEMCONFLICTMALLOCDELINST ,
- IDS_MEMCONFLICTMALLOCDELDESC ,
- CPP_MemConflictMallocDelete
- } ,
- {
- IDS_MEMCONFLICTNEWFREEINST ,
- IDS_MEMCONFLICTNEWFREEDESC ,
- CPP_MemConflictNewFree
- } ,
- { NULL } ,
- { NULL }
- } ,
- {// Pointer references unlocked memory block
- {
- IDS_PTRREFSUNLOCKEDBLOCKINST ,
- IDS_PTRREFSUNLOCKEDBLOCKDESC ,
- Pointer_PtrRefsUnlockedBlock ,
- } ,
- { NULL } ,
- { NULL } ,
- { NULL } ,
- } ,
- #ifndef BCBVER
- {// Reading overflows memory
- {
- IDS_READOVERFLOWSSTRUCTINST ,
- IDS_READOVERFLOWSSTRUCTDESC ,
- Read_ReadOverflowsStructure
- } ,
- { NULL } ,
- { NULL } ,
- { NULL } ,
- } ,
- {// Reading uninitialized memory
- {
- IDS_READUNINITMEMINST ,
- IDS_READUNINITMEMDESC ,
- Read_ReadUninitMem ,
- } ,
- { NULL } ,
- { NULL } ,
- { NULL } ,
- } ,
- #endif
- {// Stack memory overrun
- {
- IDS_STACKMEMOVERRUNINST ,
- IDS_STACKMEMOVERRUNDESC ,
- Write_StackMemOverrun ,
- } ,
- { NULL } ,
- { NULL } ,
- { NULL } ,
- } ,
- {// Static memory overrun
- {
- IDS_STATICMEMOVERRUNINST ,
- IDS_STATICMEMOVERRUNDESC ,
- Write_StaticMemOverrun ,
- } ,
- { NULL } ,
- { NULL } ,
- { NULL } ,
- } ,
- #ifndef BCBVER
- {// Writing overflows memory
- {
- IDS_WRITEOVERFLOWSMEMINST ,
- IDS_WRITEOVERFLOWSMEMDESC ,
- Write_WriteOverflowsMem ,
- } ,
- { NULL } ,
- { NULL } ,
- { NULL } ,
- } ,
-
-
- ///////////////////////////////////////////////////////////////////////////////
- // POINTER AND LEAK ERRORS
- {// Array index out of range
- {
- IDS_ARRAYPARAMEXRANGEINST ,
- IDS_ARRAYPARAMEXRANGEDESC ,
- Pointer_ArrayParamExRange ,
- } ,
- { NULL } ,
- { NULL } ,
- { NULL } ,
- } ,
- {// Assigning pointer out of range
- {
- IDS_ASSIGNPTROUTOFRANGEINST,
- IDS_ASSIGNPTROUTOFRANGEDESC,
- Pointer_AssignOutOfRange ,
- } ,
- { NULL } ,
- { NULL } ,
- { NULL } ,
- } ,
- {// Expression uses unrelated pointers
- {
- IDS_EXPRUSESUNRELPTRINST ,
- IDS_EXPRUSESUNRELPTRDESC ,
- Pointer_ExprUsesUnrelPtrs ,
- } ,
- {
- IDS_EXPRSUBSUNRELPTRSINST ,
- IDS_EXPRSUBSUNRELPTRSDESC ,
- Pointer_ExprSubsUnrelPtrs ,
- } ,
- { NULL } ,
- { NULL } ,
- } ,
- {// Expression uses dangling pointer
- {
- IDS_EXPRUSESDANGLPTRINST ,
- IDS_EXPRUSESDANGLPTRDESC ,
- Pointer_ExprUsesDanglPtr ,
- } ,
- { NULL } ,
- { NULL } ,
- { NULL } ,
- } ,
- {// Function pointer is not a function
- {
- IDS_FNPTRNOTAFNINST ,
- IDS_FNPTRNOTAFNDESC ,
- Pointer_FuncPtrIsNotAFn ,
- } ,
- { NULL } ,
- { NULL } ,
- { NULL } ,
- } ,
- #endif
- {// Interface leak
- {
- IDS_OLEINTFLEAK ,
- IDS_OLEINTFLEAKDESC ,
- OLE_Interface_Leak ,
- } ,
- { NULL } ,
- { NULL } ,
- { NULL } ,
- } ,
- {// Memory leak
- {
- IDS_MEMORYLEAKINST ,
- IDS_MEMORYLEAKDESC ,
- Leak_MemoryLeak ,
- } ,
- { NULL } ,
- { NULL } ,
- { NULL } ,
- } ,
- #ifndef BCBVER
- {// Memory leaked due to free
- {
- IDS_MEMLEAKFROMFREEINST ,
- IDS_MEMLEAKFROMFREEDESC ,
- Leak_LeakFromFree ,
- } ,
- { NULL } ,
- { NULL } ,
- { NULL } ,
- } ,
- {// Memory leaked due to reassignment
- {
- IDS_MEMLEAKFROMREASSIGNINST ,
- IDS_MEMLEAKFROMREASSIGNDESC ,
- Leak_LeakFromReassign ,
- } ,
- { NULL } ,
- { NULL } ,
- { NULL } ,
- } ,
- {// Memory leaked leaving scope
- {
- IDS_MEMLEAKFROMIGNOREINST ,
- IDS_MEMLEAKFROMIGNOREDESC ,
- Leak_LeakFromIgnore ,
- } ,
- {
- IDS_MEMLEAKFROMSCOPEINST ,
- IDS_MEMLEAKFROMSCOPEDESC ,
- Leak_LeakFromScope ,
- } ,
- { NULL } ,
- { NULL } ,
- } ,
- #endif
- {// Resource leak
- {
- IDS_RESLEAKBITMAPINST ,
- IDS_RESLEAKBITMAPDESC ,
- Leak_ResLeakBitmap ,
- } ,
- {
- IDS_RESLEAKMETAINST ,
- IDS_RESLEAKMETADESC ,
- Leak_ResLeakMetafile ,
- } ,
- {
- IDS_RESLEAKMENUINST ,
- IDS_RESLEAKMENUDESC ,
- Leak_ResLeakMenu ,
- } ,
- { NULL } ,
- } ,
- #ifndef BCBVER
- {// Returning pointer to local variable
- {
- IDS_RETURNINGPTRTOLOCALVARINST,
- IDS_RETURNINGPTRTOLOCALVARDESC,
- Pointer_ReturnPtrToLocalVar,
- } ,
- { NULL } ,
- { NULL } ,
- { NULL } ,
- } ,
- #endif
- {// Unallocated pointer
- {
- IDS_UNALLOCDPTRINST ,
- IDS_UNALLOCDPTRDESC ,
- Pointer_UnallocdPtr ,
- } ,
- { NULL } ,
- { NULL } ,
- { NULL } ,
- } ,
-
- } ;
-
- ////////////////////////////////////////////////////////////////////////
- // BCERROR normal functions start here.
- ////////////////////////////////////////////////////////////////////////
-
- void DeleteLParam ( )
- {
- for ( int i = 0 ; i < g_nLParam ; i++ )
- {
- delete g_lParamArray[ i ] ;
- }
- }
-
- HTREEITEM GetChildWithName ( HWND hWnd , HTREEITEM hParent , LPCTSTR szName )
- {
- ASSERT ( IsWindow ( hWnd ) ) ;
- HTREEITEM hChild = TreeCtrl_GetChildItem ( hWnd , hParent ) ;
-
- while ( NULL != hChild )
- {
- TV_ITEM tviChild ;
- TCHAR szChildText [ 1024 ] ;
-
- tviChild.mask = TVIF_TEXT | TVIF_HANDLE ;
- tviChild.hItem = hChild ;
- tviChild.pszText = & ( szChildText[0] ) ;
- tviChild.cchTextMax = 1024 ;
-
- if ( TreeView_GetItem ( hWnd , & tviChild ) )
- {
- if ( 0 == lstrcmp ( szName , szChildText ) )
- {
- return hChild ;
- }
- }
-
- hChild = TreeView_GetNextItem ( hWnd , hChild , TVGN_NEXT ) ;
- }
-
- return NULL ;
- }
-
-
-
- // The function to fill the tree control.
- void FillTree ( HWND hwndTree )
- {
- // The insert structure used throughout the function.
- TV_INSERTSTRUCT stTVIS ;
- HTREEITEM hItemLevel1 ;
-
- g_nLParam = 0 ;
-
- // Set up the insert structure.
- memset ( &stTVIS , NULL , sizeof ( TV_INSERTSTRUCT ) ) ;
- stTVIS.hParent = NULL ;
- stTVIS.hInsertAfter = TVI_SORT ;
- stTVIS.item.mask = TVIF_TEXT | TVIF_PARAM ;
-
- // Start with the root objects array.
- ErrorCatagory * pstEC = g_RootObjects ;
- // The buffer we use to load the strings into.
- TCHAR szBuff[ 1024 ] ;
- // The current point we are at in the type array.
- int iCurrTypes = 0 ;
- // The current point we are at in the occupancy array.
- int iCurrErrorOccur = 0 ;
-
- // While we are not done with the root object array.
- while ( 0 != pstEC->uiCatagory )
- {
- // When filling root objects, always force the
- // parent to NULL.
- stTVIS.hParent = NULL ;
-
- // The root object category string is used as the text so load it.
- VERIFY ( ::LoadString ( GetModuleHandle ( szModName ) ,
- pstEC->uiCatagory ,
- szBuff ,
- sizeof ( szBuff ) ) ) ;
- // Set the text for the item.
- stTVIS.item.pszText = szBuff ;
- // Allocate the structure that we store in the lParam field.
- LParamInfo * pLPI = new LParamInfo ;
- g_lParamArray[ g_nLParam++ ] = pLPI ;
-
- // This is a root object.
- pLPI->iType = 0 ;
- pLPI->hModule = GetModuleHandle ( szModName ) ;
-
- // Set the union to the current value.
- pLPI->stEC = *pstEC ;
- // Set the lParam and insert it saving off the HTREEITEM.
- stTVIS.item.lParam = (LPARAM)pLPI ;
-
- hItemLevel1 = GetChildWithName ( hwndTree , stTVIS.hParent , szBuff ) ;
-
- if ( NULL == hItemLevel1 )
- hItemLevel1 = TreeCtrl_InsertItem ( hwndTree , &stTVIS ) ;
-
- // Now fill in the error types for this root object.
- // Get the current part of the two dimensional types array and
- // loop until we hit the NULL value.
- ErrorType * pstET = g_ArrayOfTypes[ iCurrTypes ] ;
- while ( 0 != pstET->uiError )
- {
- // The parent for the current type.
- stTVIS.hParent = hItemLevel1 ;
- // The error string serves as the text for the tree so load it
- // and set it.
- VERIFY ( ::LoadString ( GetModuleHandle ( szModName ) ,
- pstET->uiError ,
- szBuff ,
- sizeof ( szBuff ) ) ) ;
- stTVIS.item.pszText = szBuff ;
- // Allocate the structure we set in lParam.
- pLPI = new LParamInfo ;
- g_lParamArray[ g_nLParam++ ] = pLPI ;
- // This is a level one item.
- pLPI->iType = 1 ;
- pLPI->stET = *pstET ;
- pLPI->hModule = GetModuleHandle ( szModName ) ;
- // Set the lParam and insert it into the tree.
- stTVIS.item.lParam = (LPARAM)pLPI ;
-
- HTREEITEM hItem = GetChildWithName ( hwndTree , stTVIS.hParent , szBuff ) ;
- if ( NULL == hItem )
- hItem = TreeCtrl_InsertItem ( hwndTree , &stTVIS ) ;
-
- // Fill in the error occurrences (leaves) for this type.
- // Get the current portion of the two dimensional occurrence
- // array.
- ErrorOccurance * pstEO = g_aOccurArray[ iCurrErrorOccur ] ;
- stTVIS.hParent = hItem ;
-
- while ( 0 != pstEO->uiInstance )
- {
- // The instance serves as the text for the tree. Load it
- // and set it.
- VERIFY ( ::LoadString ( GetModuleHandle ( szModName ) ,
- pstEO->uiInstance ,
- szBuff ,
- sizeof ( szBuff ) ) ) ;
- stTVIS.item.pszText = szBuff ;
- // Allocate the structure we put in lParam.
- pLPI = new LParamInfo ;
- g_lParamArray[ g_nLParam++ ] = pLPI ;
- // This is a leaf node.
- pLPI->iType = 2 ;
- pLPI->stEO = *pstEO ;
- pLPI->hModule = GetModuleHandle ( szModName ) ;
- // Set the lParam and insert it.
- stTVIS.item.lParam = (LPARAM)pLPI ;
-
- if ( NULL == GetChildWithName ( hwndTree , stTVIS.hParent , szBuff ) )
- TreeCtrl_InsertItem ( hwndTree , &stTVIS ) ;
- // Get the next item in the occurrence array.
- pstEO++ ;
- }
- // Get the next error type.
- pstET++ ;
- // Bump up the occurrence item index.
- iCurrErrorOccur++ ;
- }
- // Bump up the types item index.
- iCurrTypes++ ;
- // Get the next category.
- pstEC++ ;
- }
-
- TreeView_SelectItem ( hwndTree , hItemLevel1 ) ;
-
- }
-
- extern "C" __declspec(dllexport)
- void DoRandomErrors ( void )
- {
- // Reseed each time.
- srand( (unsigned) time( NULL ) ) ;
-
- for ( int iLoop = 0 ; iLoop < constNumRandomFuncs ; iLoop++ )
- {
- // Pick one of the error types to do.
- int iType = rand ( ) % constMaxNumErrorFuncs ;
-
- // Now pick one of the occurrences for this type.
- // Since many have just one item, we will check for that occurrence
- // as a special case. If it does have a single item, then we
- // will just call it.
- if ( NULL == g_aOccurArray[ iType ][ 1 ].pFunc )
- {
- // Double check that the function is not NULL. If it is, then
- // we will not call it.
- if ( NULL != g_aOccurArray[ iType ][ 0 ].pFunc )
- {
- g_aOccurArray[ iType ][ 0 ].pFunc ( ) ;
- }
- }
- else
- {
- // We have one of the rare ones that have multiple functions.
- // We will loop looking for a random valid one, then call it.
- int iOccur ;
- do
- {
- iOccur = rand ( ) % constMaxErrsPerType ;
- }
- while ( NULL == g_aOccurArray[ iType ][ iOccur ].pFunc ) ;
- g_aOccurArray[ iType ][ iOccur ].pFunc ( ) ;
- }
- }
- }
-
- static BOOL g_DoingAllErrors = FALSE ;
- extern "C" __declspec(dllexport)
- void DoAllErrors ( void )
- {
- // Unfortunately, there are several functions which will bring down
- // BugBench when they are called. Generally, anything that writes
- // to an uninitialized stack pointer will cause this. Since we
- // don't want to wipe out at the first one (freeing local memory)
- // we have to set the special flag so those functions can skip
- // themselves if need be!
- g_DoingAllErrors = TRUE ;
-
- // Loop through all items in g_aOccurArray and if there is a function
- // to call, call it.
- for ( int iType = 0 ; iType < constMaxNumErrorFuncs ; iType++ )
- {
- for ( int iOccur = 0 ; iOccur < constMaxErrsPerType ; iOccur++ )
- {
- if ( NULL == g_aOccurArray[ iType ][ iOccur ].pFunc )
- break ;
- g_aOccurArray[ iType ][ iOccur ].pFunc ( ) ;
- }
- }
-
- // Reset the flag.
- g_DoingAllErrors = FALSE ;
- }
-
- BOOL DoingAllErrors ( void )
- {
- return ( g_DoingAllErrors ) ;
- }
-