Replace vsprintf with vsnprintf and sprintf with strcpy