On a windowing terminal, you may have multiple windows of arbitrary size. The error message out of storage might have appeared as a result of running prog in a window with too few lines. In other words, that may have been one of the situations in which mymalloc() was called with a negative number. Now you want to be sure that when the program aborts in this situation in the future, it does so after printing the more meaningful error message screen too small. Edit the function dispinit() as follows.
cscope Function: Correcting the Problem:
/* initialize display parameters */ void dispinit() { /* calculate the maximum displayed reference lines */ lastdispline = FLDLINE - 4; mdisprefs = lastdispline - REFLINE + 1; if (mdisprefs <= 0) { (void) fprintf(stderr,"\n%s: screen too small\n", argv0); exit(1); } if (mdisprefs > 9) mdisprefs = 9; /* allocate the displayed line array */ displine = (int *) mymalloc(mdisprefs * sizeof(int)); } ^L/* display a page of the references */ void display()
You have fixed the problem we began investigating at the beginning of this section. Now if prog is run in a window with too few lines, it does not simply fail with the unedifying error message out of storage. Instead, it checks the window size and generates a more meaningful error message before exiting.