title: How do i fix this buffer overflow issue?
body: <p>I recently ran a code scan on a project i'm working on using HP fortify.
  It reported that I have a critical issue with ReadFile.
  I never pass an empty buffer.
  Any suggestions on how to fix the potential buffer overflow problem.</p>
  
  <p><strong>The Abstract</strong></p>
  
  <p>The function Read() in serialport.cpp might be able to write outside the bounds of allocated memory on line 225, which could corrupt data, cause the program to crash, or lead to the execution of malicious code.</p>
  
  <pre><code>DWORD serialport::Read(std::vector&lt;char&gt; &amp; buffer)
  {
      DWORD read = 0;
      int val = ReadFile(h, &amp;buffer[0], buffer.size(), &amp;read, NULL);
  
      if (val == 0)
      {
          LPCSTR ptr = "";
          PrintError(ptr);
      }
  
      buffer.resize(read);
      return read;
  }
  </code></pre>