CleverRaven/Cataclysm-DDA — pull request #8582 by BevapDin (2014-08-15 10:23:47+00:00)
Title: Fix SDL crash

Fixes #8536

I'm wondering why this has never failed. The crashing function (`clearok`) exists in that form since the dawn of time (7ba00561e8f0ad89a727260e84b77eaf244cf8b8).

Windows are created with `newwin`. It allocates enough memory for all the lines `newwindow->line = new curseline[nlines]` (nlines is the height). Small windows at the bottom of the screen would have for example `nlines=10` (height) and `y=40` (y is the vertical position). The loop in `clearok` would fail as it goes up to line 39, while there are only 10 lines. Clearly the loop condition is not sufficient to prevent an out-of-bounds access of the array.

For some reason this scenario never happened. Probably because `clearok` is only called by `wclear`, which was called only called with the main window as parameter from `clear()`. And with the main window as parameter it works fine by definition as the main window has y=0. Recently a second call to `wclear` has been added in worldfactory.cpp (during display of the mods).

The window with the mods (which has always the same constant height) is placed in the center of the screen and if the screen is large enough that makes the y-position of the window large, and in those circumstances the y value is too large and triggers the crash above.

Fixed by using `werase` as *every* other part of the code does.

And fixed `clearok`, just in case. Setting the `touched[i]` of the window to true there is a bit pointless as the function is called right after `werase`, which already sets `touched[i]` to true. `clearok` should trigger the redrawing of the whole screen.