title: Warning - Conversion from size_t to DWORD, possible loss of data
body: <p>I'm building a 64bit C++ code on VS 2015.</p>
  
  <pre><code>DWORD blockLength;
  blockLength = strlen((LPCSTR)sourceVar);    // sourceVar is of type Cstring, build warning here. 
  
  // Allocate memory.
  defaultBuffer = new unsigned char[blockLength + 1];
  
  sprintf_s(reinterpret_cast&lt;char*&gt;(defaultBuffer), (blockLength + 1), "%s", (LPCSTR)sourceVar); 
  
  // Decrypt data
  if (!someMethod(someParameter, 0, 1, 0, defaultBuffer, &amp;blockLength))
  {
  // Do something
  }
  </code></pre>
  
  <p>When I run the code from HP-fortify, I don't see any build warnings or any fortify issues. </p>
  
  <p>However, when I build the code separately, I see this <strong>warning</strong> on 2nd line -</p>
  
  <pre><code>warning C4267: '=': conversion from 'size_t' to 'DWORD', possible loss of data
  </code></pre>
  
  <p>Now, <strong>when I make these code changes</strong> - </p>
  
  <pre><code>blockLength = sourceVar.GetLength();
  </code></pre>
  
  <p>The build warning is gone. However, when I run this new code against <strong>HP-Fortify</strong>, I now see following error at sprintf_s line - </p>
  
  <p>Buffer Overflow
  (Input Validation and Representation, Data Flow)  - 
  The function writes outside the bounds of allocated memory, which could corrupt data, cause the program to crash, or lead to the execution of malicious code.</p>