Change the logic to not require format strings to be defined thereby avoiding potential segfaults.
Avoid using strnlen() and instead use memcpy().
More memory is used when specifying the sizes, but strnlen() calls probably does this to some extent.
Doing this reduces the number of calls to copying ranges of strings.