title: Why am I getting Run-Time Check Failure #2 - Stack around the variable 'x' was corrupted?
body: <p>This is driving me crazy. I have legacy code where I added few more conditions (below). I am parsing a string and retrieving the data. This is how it is done in legacy code so I haven't changed the style.</p>
  
  <pre><code>        WORD wPSM = 0;
          double dblPST = 0;
          WORD wSDB = 0;
  
          if(-1 != str.Find("PSM="))
          {
              nNumScanned = sscanf_s((LPCTSTR) str, "PSM=%u", &amp;wPSM);
          }
          if(-1 != str.Find("PST="))
          {
              nNumScanned = sscanf_s((LPCTSTR) str, "PST=%lf", &amp;dblPST);
          }
          if(-1 != str.Find("SDB="))
          {
              nNumScanned = sscanf_s((LPCTSTR) str, "SDB=%u", &amp;wSDB);
          }
  </code></pre>
  
  <p>I get error <code>Run-Time Check Failure #2 - Stack around the variable 'wPSM' was corrupted</code>. I don't get this error if I commented these three lines. <code>str</code> is CString and it does contain the expected value. </p>
  
  <p>Is there something wrong with <code>sscanf_s</code> syntax above that maybe causing this?</p>
  
  <p>Note this is c++ project with VS2010, I have marked it C only to draw attention because of sscanf_s</p>