title: How to avoid __builtin___memset_chk warning?
body: <p>I am running gcc 4.8.4 and compiling with options:</p>
  
  <pre><code>CXXFLAGS+= -Wall -std=c++11 -pedantic -lpthread
  </code></pre>
  
  <p>I want to zero a structure using memset:</p>
  
  <pre><code>typedef struct
  {
      TSfMsgHeader    errorHeader;
      TErrorHeader    errorType;
      TErrorDetails   errorDetails;
  }TErrorInd;
  
  uint8 g_errorIndBlock[16];
  
  TErrorInd* p_msg = (TErrorInd *)&amp;g_errorIndBlock[0];
  memset((int*)p_msg, 0, sizeof(TErrorInd));
  </code></pre>
  
  <p>This results in warning:</p>
  
  <blockquote>
    <p>In function ‘void* memset(void*, int, size_t)’,
        inlined from ‘void sendMsgPduError(TMsgPduError*, uint32)’ at ../MessageHandling.cpp:174:46:</p>
    
    <p>/usr/include/x86_64-linux-gnu/bits/string3.h:84:70: warning: call to void* __builtin___memset_chk(void*, int, long unsigned int, long unsigned int) will always overflow destination buffer [enabled by default]</p>
    
    <p>return __builtin___memset_chk (__dest, __ch, __len, __bos0 (__dest));</p>
  </blockquote>
  
  <p>I realise that this is a sensible warning but I don't know how to modify the code to fix it.</p>
  
  <p>I read that std::fill_n is preferred to memset. Is that correct?</p>
  
  <p>If so, how would I replace memset by fill_n?</p>