From: SMTP%"DSJ@WKUVX1.WKU.EDU" 21-DEC-1993 10:51:36.10 To: EVERHART CC: Subj: OCTOBER93.CBUGS X-FileServer: Digital Systems Journal File Server Date: Tue, 21 Dec 1993 09:55:03 CDT Sender: DSJ-Mgr@WKUVX1.WKU.EDU Errors-To: DSJ-Mgr@WKUVX1.WKU.EDU Warnings-To: <> From: DSJ-Mgr@WKUVX1.WKU.EDU Reply-To: DSJ@WKUVX1.WKU.EDU Subject: OCTOBER93.CBUGS To: EVERHART@arisia.gce.com int *x = new int [20]; // Set up an array of 20 ints ... // Do useful stuff with the array delete [] x; // Return the memory to the free // store. == void set_new_handler( void (*)(void)) == char string[80]; ... scanf("%s",string); == char string[80]; ... cin >> string; == istream &get(char *ptr, int len, char delim) istream &getline(char *ptr, int len, char delim) == $ $ type new_handler.cxx // Program illustrating the establishment of a "new" // handler #include #include #include void mem_problem(void); in main(void) { int i; int *x; // Establish a handler function for problems with new // i.e. returns a NULL value set_new_handler(mem_problem); // Ask for memory which is too big i=2000000000; x = new int [i]; // Should not get here printf("last element = %d\n",x[i-1]); return(EXIT_SUCCESS); } // Generate system dependent message #ifdef __VMS const char *local_msg = "See the system manager and ask " "her/him to increase\n" "The sysgen parameter VIRTUALPAGECNT.\n; #else const char *local_msg = "Locate the UNIX Guru and pray!\n"; #endif void mem_problem(void) { perror("Memory allocation failure detected, aborting!\n"); fprintf(stderr,local_msg); // Lunch the program exit(EXIT_FAILURE); } $ $ $ cxx new_handler $ link new_handler $ run new_handler Memory allocation failure detected, aborting! : not enough core See the system manager and ask her/him to increase The sysgen parameter VIRTUALPAGECNT. $ $ == $ $ type new_prob.cxx // Program illustrating the establishment of a "new" // handler #include #include #include void mem_problem(void); int main(void) { int i; int *x; // Establish a handler function for problems with new // i.e. returns a NULL value set_new_handler(mem_problem); // Keep asking for memory until too much i=20000; for(int j=0;j<10000;j++) x = new int [i]; // Should not get here printf("last element = %d\n",x[i-1]); return(EXIT_SUCCESS); } // Generate system dependent message #ifdef __VMS const char *local_msg = "See the system manager and ask " "her/him to increase\n" "The sysgen parameter VIRTUALPAGECNT.\n"; #else const char *local_msg = "Locate the UNIX Guru and pray!\n"; #endif void mem_problem(void) { perror("Memory allocation failure detected, aborting!\n"); fprintf(stderr,local_msg); // Lunch the program exit(EXIT_FAILURE); } $ $ !Note: The bogus error message $ cxx new_prob $ link new_prob $ run new_prob %SYSTEM-F-ACCVIO, access violation, reason mask=05, virtual address=7FF248BC, PC=0007EC16, PSL=0BC00009 Improperly handled condition, image exit forced. Signal arguments Stack contents %SYSTEM-F-ROPRAND, reserved operand fault at PC=80000010, PSL=03C00004 Improperly handled condition, image exit forced. Signal argument Stack contents Number = 0000000 80223840 Name = 00000454 00000002 80000010 7FF273F0 03C00004 7FF273D8 00000004 7FF270FC 00000007 00000000 80223C00 Register dump R0 = 03C00000 R1 = 00040000 R2 = 000000FC R3 = 7FF274EC R4 = 00000000 R5 = 00000004 R6 = 7FF275EC R7 = 7FF2746D R8 = 7FF27600 R9 = 7FF27454 R10= 7FF274EC R11= 7FF274A8 AP = 7FF27394 FP = 7FF27354 SP = 7FF273C8 PC = 80000010 PSL= 03C00004 $ $ == $ type new_kluge.cxx // Program illustrating the establishment of a "new" // handler #include #include #include #include void mem_problem(void); int main(void) { int i; int *x; // Establish a handler function for problems with new // i.e. returns a NULL value set_new_handler(mem_problem); //******* Kluge fix // Send a warning, to activate perror and prevent later problems errno = EINPROGRESS; perror("Setting up arrays"); //******* // Keep asking for memory until too much i=20000; for(int j=0;j<10000;j++) x = new int [i]; // Should not get here printf("last element = %d\n",x[i-1]); return(EXIT_SUCCESS); } // Generate system dependent message #ifdef __VMS const char *local_msg = "See the system manager and ask " "her/him to increase\n" "The sysgen parameter VIRTUALPAGECNT.\n"; #else const char *local_msg = "Locate the UNIX Guru and pray!\n"; #endif void mem_problem(void) { perror("Memory allocation failure detected, aborting!\n"); fprintf(stderr,local_msg); // Lunch the program exit(EXIT_FAILURE); } $ cxx new_kluge $ link new_kluge $ r new_kluge Setting up arrays: operation in progress Memory allocation failure detected, aborting! : not enough core See the system manager and ask her/him to increase The sysgen parameter VIRTUALPAGECNT. $ == [Figure 4] $ type read_bad.cxx #include #include const static int max_lines = 5; const static int in_bufsize = 30; int main(void) { char strings[max_lines][in_bufsize]; char last_char; // Prompt user cout << "Enter up to "< #include const static int max_lines = 5; const static int in_bufsize = 30; int main(void) { //************** // Compensate for cin.get //************** char strings[max_lines][in_bufsize + 1] = {0}; char last_char; // Prompt user cout << "Enter up to "<