text/encoding: constify arguments

Most of these functions don't modify their strings, let's make the contract
a bit clearer. In some cases I've tried to get rid of C89-style variable
declarations at the start of functions, now that I was there.
text: remove useless arg from mb_string2cells

mb_string2cells was always called like mb_string2cells(..., -1) so that was
the only codepath that was tested. @tarruda was the first to try to input an
actual length, after which valgrind detected that funny business was going
on.

It's not even possible to do the right thing with the current text codec
infrastructure: they all assume to be working with C strings. Meaning that
if there is no NUL-terminator, they will happily keep on reading past the
end of Pascal strings. Ergo, passing the length parameter is moot. The
condition in the for-loop was wrong as well (but that's no longer relevant).

Also change the return value to size_t, by analogy with strlen.

ref:
https://github.com/neovim/neovim/commit/677d30d7966dd2766bbf20665791c568dacc427a
Merge #777 'Constify text enc args fix mb_string2cells'
msgpack: NULL terminate incoming strings

It's a 1-byte loss of memory but it allows us to skip copying and
NULL-terminating strings when interacting with vim functions that accept C
strings. This lowers the pressure on the allocator and saves lines of code
(no more dup/free pairs).
api: remove some redundant string copies

Now that incoming Pascal strings are NULL-terminated by default, we can skip
some spurious copies.
api: also NUL-terminate Strings made from cstrs

I believe we can now mostly assume that all encountered String's data
members are safe to pass into functions that accept C strings. That should
simplify interop with C string code.
api: unify string conversions, simplify interop

- The data member of String's can now be passed directly to functions
  expecting C strings, as we now guarantee that they are NUL-terminated.
  This obviates the need to use xstrndup and free, simplifying code and
  enhancing performance.
- Use xmemdupz instead of xstrndup for converting String's into C strings.
  It's faster because it doesn't calculate strlen(string.data) (which is
  unnecesary as that information is already provided in string.size anyway).
- Use cstr_to_string to convert from C strings to String, it is both shorter
  and faster than the usual strlen/xstrndup combo, which calls strlen twice.
  cstr_to_string internally calls strlen and then xmemdupz.
Merge #783 'Nul terminate pascal strings'
coverity/13749: Negative array index read
coverity/62607,62608,62609: Fix variable limits

The Coverity issues regarded broken limit checks of variables. The following
changes should fix these issues.

api/buffer.c:
	- Add a proper check to catch overflows

api/window.c:
	- Remove out of range check since the function arguments are of type
	  int64_t and an out of range error is impossible in this case.
coverity/13685: Buffer not null terminated
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