Which of sprintf/snprintf is more secure?

I wish to know which of these two options is the more secure one to use:

#define MAXLEN 255
char buff[MAXLEN + 1]
  1. sprintf(buff, "%.*s", MAXLEN, name)
  2. snprintf(buff, MAXLEN, "%s", name)

My understanding is that both are same. Please suggest.

Leave a Comment