Fix a stack overflow issue caused by an invalid usage of snprintf