Change sprintf to snprintf for buffer overflow protection