title: Run-Time Check Failure #2 - Stack around the variable 'length' was corrupted
body: <blockquote>
    <p>Hi All,</p>
    
    <p>I am working on changing our application to support unicode
    characteristics . Hence while doing the changes i had to convert all
    char to wchar_t and we had some wrapper stream classes which i
    converted to support wchar_t . Now my issue is while doing the change
    to the below code i encounter Run-Time Check Failure #2 - Stack around
    the variable 'length' was corrupted. though if i continue i get the
    proper values . Please let me know how to get rid of this error.</p>
  </blockquote>
  
  <pre><code>FDIStream&amp;  
  FDIStream::
  operator&gt;&gt;(std::wstring&amp; data)
  {
      if (CanReadData())
      {
          int length = -1;
          *this &gt;&gt; length;
  
          if (length &gt;= 0)
          {
              // See if length is a valid value (not pass eof)
              if (length &gt; GetLength()) {
                  throw FDException("Corrupted file");
              }
  
              wchar_t* buffer = new wchar_t[length];
  
              try
              {
                  ReadBytes(buffer, length);
  
                  data = std::wstring(buffer,length); 
              } catch (...)
              {
                  delete[] buffer;
                  throw;
              }
  
              delete[] buffer;
          }
      }
  
      return *this;
  }
  </code></pre>