Avoid declaring unused variables

Also check the string length before doing a strncpy.