Grab string length before copying strings

This fixes a valgrind warning on newer Linux version. It's not really a
bug, but it's an easy enough workaround to fix warnings in valgrind
because of strlen() usage.