coverity/13750: Negative array index read

I copied the action that is taken in other parts of the same function to check
for a negative index returned from find_command() and inserted it at every call
site.
api: pull limit check in buffer.c and window.c out of loops

buffer.c:
  While fixing a coverity issue regarding the check for range overflows of
  variables it was proposed to pull the check out of the allocation loop. This
  allows us also to remove the end label and it's deallocations since there is
  no goto pointing to it anymore.

window.c:
  It is also possible to pull the range checks out of the loops. However since
  there are functions that should be called at the end of the functoin in any
  case we better don't remove the goto in the range checks.
options: fix coding style of previous change
api: buffer.c fix copy and paste error introduced in previous fix