FIX: unchecked mallocs

Rewrote _tmp_string_t handling in buffer.c to use the fact that
realloc(NULL, n) is equivalent to malloc(n). There are still some
unchecked cases in this file.

Also changed some arguments to const and removed casts on malloc
return values; malloc returns void*, which is converted to any
other pointer automatically. Casting the return value of malloc
is more likely to hide bugs than to fix anything.
MAINT: remove unused goto label and useless casts
FIX: some more casts in ufunc_object

Introduced a helper function to get rid of repetitive code.