title: Is this a false positive from Klocwork
body: <p><em>Background</em></p>
  
  <p>Consider the following code:</p>
  
  <pre><code>    template &lt;typename T&gt;
      void WriteData(const size_t &amp;offset, const T &amp;data)
      {
          if(sizeof(data) &lt;= 8) //if size is 64bits or less, memcpy is not as efficient as a direct write
              *reinterpret_cast&lt;T*&gt;(reinterpret_cast&lt;char*&gt;(_memView) + offset) = data;
         else
          {
              errno_t result = memcpy_s(reinterpret_cast&lt;char*&gt;(_memView) + offset, SHARED_BUFFER_SIZE - offset, &amp;data, sizeof(data));
              if(result != 0)
                  throw exception("Error writing data");
          }
      }
  </code></pre>
  
  <p>Assume that _memView is declared as a void pointer.
  memcpy_s has NOT been redefined anywhere.</p>
  
  <p>The function is only ever instantiated with the following types: char, int, HANDLE, unsigned int, long and unsigned long. Don't get bogged down in the other issues with this snippet, this is about klocwork.</p>
  
  <p>This templated code is part of a class, and so this sits in a header file.</p>
  
  <p>If i'm missing other relevent information just ask.</p>
  
  <p><em>The Issue</em></p>
  
  <p>After analysis with Klocwork, i'm getting the SV.BANNED.COPY warning: "Do not use unsafe buffer copy functions -- consider using a safe variant such as strcpy_s"</p>
  
  <p>So am i doing something brain dead here with the way I'm calling memcpy_s, is memcpy_s considered insecure by Klocwork? Is Klocwork confused by the casting to char* and thinking i'm manipulating a C style string?</p>
  
  <p>I'd like to understand what Klocwork is trying to tell me, even if it's just telling me it is a false positive.</p>