title: sprintf_s with a buffer too small
body: <p>The following code causes an error and kills my application. It makes sense as the buffer is only 10 bytes long and the text is 22 bytes long (buffer overflow). </p>
  
  <pre><code>char buffer[10];    
  int length = sprintf_s( buffer, 10, "1234567890.1234567890." ); 
  </code></pre>
  
  <p>How do I catch this error so I can report it instead of crashing my application? </p>
  
  <p><strong>Edit:</strong></p>
  
  <p>After reading the comments below I went with _snprintf_s.  If it returns a -1 value then the buffer was not updated.</p>
  
  <pre><code>length = _snprintf_s( buffer, 10, 9, "123456789" );
  printf( "1) Length=%d\n", length ); // Length == 9
  
  length = _snprintf_s( buffer, 10, 9, "1234567890.1234567890." );
  printf( "2) Length=%d\n", length ); // Length == -1
  
  length = _snprintf_s( buffer, 10, 10, "1234567890.1234567890." );
  printf( "3) Length=%d\n", length ); // Crash, it needs room for the NULL char 
  </code></pre>