Why is 'n' parameter of snprintf ignored?
snprintf() will not write more than &lt;size&gt; (snprintf's 2d argument) characters to your buffer, but it does count (and discard the extra) characters it would have written, had there been space enough, and that is the number it returns. Yeah, it can be confusing!

See this snprintf() reference.