do not copy invalid data by using strncpy instead of memcpy