Add bufsiz parameter to mbs_safe_encode_to_buffer() and
mbs_invalid_encode_to_buffer() functions to enable safe buffer
operations. Track remaining buffer size internally using int
variable and convert all sprintf() calls to snprintf().
Add buffer overflow protection by checking snprintf() return
values and verifying sufficient space before memcpy() and
direct writes. Break encoding loop early if buffer space
is exhausted.
This change improves code safety by preventing potential buffer
overflows and makes buffer size limits explicit in the API.