does this:
end = memchr(s, '\0', n);
if (end != NULL)
n = end - s;
is that just to avoid allocating an extra byte if 's' already contains
'\0' at the end? seem like it would be better to waste the extra byte
than to scan the whole string with memchr() or at least change that to:
if (*(s + (n-1)) == '\0') {
n--;
}
?
