[RFC] Coverity Issues

This PR fixes several Coverity issues listed in #760 , namely 13796, 62607, 62608, 62609, 62612, 62615. Additionally I found that some of the Coverity defects are false positives, especially in the ressource leak category.

I couldn't find how to mark them as false positives in the Coverity web interface though. I suspect that my role of contributer doesn't have sufficient rights to do so.
Looking further into this I think it won't be easy to keep the former behaviour with the range check outside the loop. I came up with the following wich seems to be equivalent to the former code:
```c
bool out_of_range_error = false;
if ((int64_t)to_replace > LONG_MAX - start) {
  to_replace = LONG_MAX - start;
  out_of_range_error = true;
}

size_t i;
for(i = 0; i < to_replace, i++) {
  int64_t lnum = start + (int64_t)i;

  if (ml_replace((linenr_T)lnum, (char_u *)lines[i], false) == FAIL) {
    set_api_error("Cannot replace line", err);
    goto end;
  }
}
if (out_of_range_error) {
  set_api_error("Index value is too high", err);
  goto end;
}
lines[i] = NULL;
```
I don't really like this solution becaue it scatters the detection of the error and the actions to take. In my opinion those things belong in one place.

I think it's preferable to break up with the former behaviour instead of trying to stay compatible. As far as I see it we do not have to keep the API stable before a first stable release or at least a formal API freeze. If however general consesus is to stay compatible to the former solution I don't mind to change the code as proposed.