Issue #988: Use safe string functions for copying values

Fix coverity issues in #988 by using safe string functions