⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bcsample.cpp

📁 DOS环境下C/C++语言内存问题检测 numega的产品
💻 CPP
📖 第 1 页 / 共 2 页
字号:
printf("\n\n\n\n\n\n\n\n\n\n");
printf("          To see this screen in BOUNDS-CHECKER, press '/'\n");
printf("\n");
printf("            Press any key to cause this program defect");
getch();
}

void screen3()
{

printf("\n      Pass A Library Routine An Out-Of-Bounds Pointer\n");
printf("\n");
printf("This example is to show what happens when an exception occurs in\n");
printf("a routine that has NOT been compiled with debug information.\n");
printf("\n");
printf("After you press a key, a bad pointer will be passed to a library routine.\n");
printf("BOUNDS-CHECKER will pop up immediately, stating that an out-of-bounds\n");
printf("access has occurred for a routine that does not have source available.\n");
printf("After pressing a key the call stack will be displayed.\n");
printf("Routines that have source available are preceded with '#'.\n");
printf("\n");
printf("You can select routines to display using the arrow keys followed by\n");
printf("enter.  To get back to the call stack select 'Stack' on the main menu.\n");
printf("After you have viewed the source, select 'Log' on the main menu.\n");
printf("Logging the access will cause relevant information  to be placed\n");
printf("in the log file.  The program will continue running and the\n");
printf("library routine will use the bad pointer.  Memory, however, will not be\n");
printf("corrupted by using 'Log' instead of 'Mark' because this is a memory\n");
printf("read instead of a memory write as shown in previous examples.\n");
printf("\n\n");
printf("          To see this screen in BOUNDS-CHECKER, press '/'\n");
printf("\n");
printf("            Press any key to cause this program defect");
getch();
}

void screen4()
{
printf("\n               Make A Legal Out-Of-BOUNDS Access\n");
printf("\n");
printf("This example accesses a commonly used BIOS variable.  Many programs\n");
printf("access BIOS variables and other system memory locations intentionally\n");
printf("These memory accesses can be added to BOUNDS-CHECKER's exception list\n");
printf("so it does not pop up every time you run the program.\n");
printf("\n");
printf("Select 'Add' at BOUNDS-CHECKER's main menu.  Then select 'Read',\n");
printf("'Procedure' and 'Location' as you are prompted.  This tells\n");
printf("BOUNDS-CHECKER that any access to memory location 40:10H by the\n");
printf("procedure 'LegalAccess' is valid and should not be considered a bug.\n");
printf("\n\n\n\n\n\n\n\n\n\n");
printf("          To see this screen in BOUNDS-CHECKER, press '/'\n");
printf("\n");
printf("            Press any key to cause this program defect");
getch();
}
void screen5()
{
printf("\n             Cause A General Protection Violation\n");
printf("\n");
printf("After you press a key, a routine will be called that causes a FATAL\n");
printf("general protection violation.  BOUNDS-CHECKER will pop up when this\n");
printf("occurs, but you can not continue to run this sample program.  You must\n");
printf("exit by selecting 'eXit' at the main menu.\n");
printf("\n");
printf("When a protection violation or invalid op-code exception occurs in a\n");
printf("program that you are debugging you typically want to display a call\n");
printf("stack by selecting 'Stack' at the main menu).  This gives you some \n");
printf("perspective on where the program was executing prior to the fault.\n");
printf("\n\n\n\n\n\n\n\n\n\n");
printf("          To see this screen in BOUNDS-CHECKER, press '/'\n");
printf("\n");
printf("            Press any key to cause this program defect");
getch();
}


void screen6()
{
printf("\n        strcpy Past The End Of A Local Character Array\n");
printf("\n");
printf("After you press a key, a routine will be called that uses the strcpy library\n");
printf("routine to copy a string to a local array.  The array is not large\n");
printf("enough to hold the string so BOUNDS-CHECKER will pop up.\n");
printf("Select 'Data_info' to see more information about the array overflow.\n");
printf("\n");
printf("When this type of problem occurs, you would normally exit BOUNDS-CHECKER.\n");
printf("For this example select 'Log' at the main menu to continue running.\n");
printf("\n\n\n\n\n\n\n\n\n\n\n\n");
printf("          To see this screen in BOUNDS-CHECKER, press '/'\n");
printf("\n");
printf("            Press any key to cause this program defect");
getch();
}

void screen7()
{
printf("\n           memcpy Past The End Of A Local Structure\n");
printf("\n");
printf("After you press a key, a routine will be called that uses the memcpy\n");
printf("library routine to copy memory past the end of a structure that was\n");
printf("defined locally (on the stack). BOUNDS-CHECKER pops up giving you\n");
printf("the opportunity to view source of calling routines on the call stack.\n");
printf("Select 'Data_info' to see more information about the structure overflow.\n");
printf("\n");
printf("Normally when this type of problem occurs, you would exit BOUNDS-\n");
printf("CHECKER with the 'eXit' option.  In this case select 'Log' at\n");
printf("BOUNDS-CHECKER's main menu so your program will continue to run.\n");
printf("\n\n\n\n\n\n\n\n\n\n");
printf("          To see this screen in BOUNDS-CHECKER, press '/'\n");
printf("\n");
printf("            Press any key to cause this program defect");
getch();
}

void screen8()
{
printf("\n         strcpy Past The End Of A Static Character Array\n");
printf("\n");
printf("After you press a key, a routine will be called that uses the strcpy library\n");
printf("routine to copy a string to a statically allocated array that is not large\n");
printf("enough to hold the string.  BOUNDS-CHECKER will pop up.  The source\n");
printf("of the routine that called strcpy is displayed in the code window.\n");
printf("Select 'Data_info' to see more information about the array overflow.\n");
printf("\n");
printf("Normally when this type of problem occurs, you would exit BOUNDS-\n");
printf("CHECKER with the 'eXit' option.  In this case select 'Log' at\n");
printf("BOUNDS-CHECKER's main menu so your program will continue to run.\n");
printf("\n\n\n\n\n\n\n\n\n\n");
printf("          To see this screen in BOUNDS-CHECKER, press '/'\n");
printf("\n");
printf("            Press any key to cause this program defect");
getch();
}

void screen9()
{
printf("\n                memset Past The End Of A malloced Block\n");
printf("\n");
printf("After you press a key, a routine will be called that uses the memcpy\n");
printf("library routine to copy data past the end of a memory block that was\n");
printf("allocated with malloc.  BOUNDS-CHECKER pops up stating that you are\n");
printf("about to over-run the block.  This type of bug typically corrupts\n");
printf("the internal heap data structures maintained by your run-time library.\n");
printf("Select 'Data_info' to see more information about the block overflow.\n");
printf("\n");
printf("This example pops up BOUNDS-CHECKER a second time when free is called.\n");
printf("This occurs because the memory block is corrupt when it is freed.\n");
printf("\n");
printf("Normally when this type of problem occurs, you would exit BOUNDS-\n");
printf("CHECKER with the 'eXit' option.  In this case select 'Log' at\n");
printf("BOUNDS-CHECKER's main menu both times it pops up.\n");
printf("\n\n\n\n\n\n");
printf("          To see this screen in BOUNDS-CHECKER, press '/'\n");
printf("\n");
printf("            Press any key to cause this program defect");
getch();
}

void screen10()
{
printf("\n     Direct Program Access Past The End Of A malloced Block\n");
printf("\n");
printf("After you press a key, a memory block will be allocated and filled with\n");
printf("0's directly (not by using library routines).  Then another malloc will be\n");
printf("called to allocate additional memory.  In this case, BOUNDS-CHECKER\n");
printf("does not pop up the instant the write past the end of the block occurs.\n");
printf("It pops up on the next call to a memory or string related library routine. In\n");
printf("this example BOUNDS-CHECKER pops up when the next malloc occurs.\n");
printf("Select 'Data_info' to see more information about the block overflow.\n");
printf("\n");
printf("To continue, select 'Log' at BOUNDS-CHECKERs main menu.\n");
printf("\n\n\n\n\n\n\n\n\n\n");
printf("          To see this screen in BOUNDS-CHECKER, press '/'\n");
printf("\n");
printf("            Press any key to cause this program defect");
getch();
}

void screen11()
{
printf("\n              Use Of Pointer To Freed Memory Block\n");
printf("\n");
printf("This example allocates a memory block, then immediately frees it. The\n");
printf("pointer returned by malloc will be used to write a character into memory.\n");
printf("BOUNDS-CHECKER will pop up immediately stating that an out-of-bounds\n");
printf("access at address 0:1.  The reason the access is at 0:1 is that\n");
printf("BOUNDS-CHECKER set the pointer to 0:1 when the block was freed.\n");
printf("This is done so the cause of the access will be easily identifiable if the\n");
printf("freed pointer is used.\n");
printf("\n");
printf("To continue, select 'Mark' on BOUNDS-CHECKER's main menu.\n");
printf("Marking places information about this exception in the .LOG file and\n");
printf("also WRITE PROTECTS the memory location, so you do not actually\n");
printf("corrupt memory.  Then your program continues to run.\n");
printf("\n\n\n\n\n\n\n");
printf("          To see this screen in BOUNDS-CHECKER, press '/'\n");
printf("\n");
printf("            Press any key to cause this program defect");
getch();
}

void screen12()
{
printf("\n                Call To Free With A Bad Pointer\n");
printf("\n");
printf("After you press a key, free will be called with a pointer to memory that is\n");
printf("not the start of a malloced block.  This type of bug usually corrupts\n");
printf("memory, because free will assume that the pointer points at a data\n");
printf("structure that it can freely manipulate.\n");
printf("\n");
printf("In this case BOUNDS-CHECKER will pop up immediately stating that free\n");
printf("was called with a bad pointer.  To see the actual address that was passed\n");
printf("select 'Data_info' . Often, the address may give you a hint on what the problem is.\n");
printf("\n");
printf("To continue, select 'Log' on the main menu.  Logging places information\n");
printf("about this exception in the .LOG file for later perusal.\n");
printf("\n\n\n\n\n\n\n");
printf("          To see this screen in BOUNDS-CHECKER, press '/'\n");
printf("\n");
printf("            Press any key to cause this program defect");
getch();
}

void screen13()
{
printf("\n        strcpy Past The End Of A Block Allocated With new\n");
printf("\n");
printf("After pressing a key, a routine will be called that uses the strcpy library\n");
printf("routine to copy a string to a memory block that is too small.  This block\n");
printf("was allocated with new.  BOUNDS-CHECKER pops up stating that you\n");
printf("are about to over-run the block.  In this case BOUNDS-CHECKER does\n");
printf("not show the source directly, but you can use the call stack to display\n");
printf("the routine that called new.  This type of bug typically corrupts internal\n");
printf("heap data structures. Select 'Data_info' to see more information\n");
printf("about the block overflow.\n");
printf("\n");
printf("This example pops up BOUNDS-CHECKER a second time when delete is called.\n");
printf("This occurs because the memory block is corrupt when it is freed.\n");
printf("\n");
printf("Normally when this type of problem occurs, you would exit BOUNDS-\n");
printf("CHECKER with the 'eXit' option.  In this case select 'Log' at BOUNDS-\n");
printf("CHECKER's main menu so the program will continue to run.\n");
printf("\n\n\n\n");
printf("          To see this screen in BOUNDS-CHECKER, press '/'\n");
printf("\n");
printf("            Press any key to cause this program defect");
getch();
}

void screen14()
{
printf("\n                Call To delete With A Bad Pointer\n");
printf("\n");
printf("After you press a key, delete will be called with a pointer to memory that\n");
printf("is not the start of an allocated block.  This type of bug usually corrupts\n");
printf("memory, because delete will assume that the pointer points at a data\n");
printf("structure that it can freely manipulate.\n");
printf("\n");
printf("In this case BOUNDS-CHECKER will pop up immediately stating that\n");
printf("free was called with a bad pointer.  This is because delete actually\n");
printf("calls free to de-allocate memory. Select 'Data_info' to see the value of\n");
printf("the bad pointer.  Often, the address may give you a hint that will help\n");
printf("solve the problem.\n");
printf("\n");
printf("To continue, select 'Log' on the main menu. Logging places information\n");
printf("about this exception in the .LOG file for later perusal.\n");
printf("\n\n\n\n\n\n");
printf("       To see this screen in BOUNDS-CHECKER, press '/'\n");
printf("\n");
printf("            Press any key to cause this program defect");
getch();
}

void screen15()
{
printf("\n      Exit With Memory Blocks Not deleted\n");
printf("\n");
printf("This example shows memory leakage with C++'s delete.\n");
printf("\n");
printf("After you press a key, a memory block will be allocated with new then\n");
printf("the program will exit.  Since the memory block has not been removed\n");
printf("with delete, BOUNDS-CHECKER will display a message on exit.\n");
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
printf("            Press any key to allocate blocks and exit");
getch();
}

void screen16()
{
printf("\n          Exit With malloced Blocks Not freed\n");
printf("\n");
printf("This example shows memory leakage of blocks allocated with malloc.\n");
printf("\n");
printf("After you press a key, a memory block will be allocated with malloc then\n");
printf("the program will exit.  Since the memory block has not been removed\n");
printf("with free, BOUNDS-CHECKER will display a message after your program\n");
printf("exits.\n");
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
printf("            Press any key to allocate blocks and exit");
getch();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -