When there was at least one search attempt, search box is still opened,
and the screen and/or history is cleared, there is a high chance that
the line number remembered by the search is invalid. The line number is
used as the lines array index, so this can lead to overflow and crash.
This is at this moment fixed with a check in copyLineToStream(), which
is a generic function that happens to be used by search function and
where the line number is used. There still is an assert which is
triggered in debug builds.
The patch moves the check directly to a search function, where the line
number is initialized before first search.