Replace sprintf with snprintf and asprintf.