Replace sprintf with snprintf