title: Why calling vprintf or similar functions twice does not work or even segfaults?
body: <p>I got a segmentation fault in my program and was able to reliably reproduce it in this simple example:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;syslog.h&gt;
  #include &lt;stdarg.h&gt;
  
  // if I remove at least one of the args, segfault does not happen
  void doLog(unsigned int arg0, unsigned int arg1, unsigned int arg2, const char* format, ...)
  {
      va_list args;
  
      va_start(args, format);
      // by default - to both console and syslog
      vprintf(format, args);
  
      // next v* function call causes segfault, no matter if vprintf or vsyslog
      //vprintf(format, args);
      vsyslog(LOG_WARNING, format, args);
      va_end(args);
  }
  
  int main(int argc, char *argv[])
  {
      // if I remove at least one of the function args or an %s in the string, the segfault does not happen
      doLog(1, 2, 3, "Format with args %s , %s", "1", "2");
  
      return 0;
  }
  </code></pre>
  
  <p>What's going on here? Why does the second call to vprintf or vsyslog causes the segfault and why does it happen only with this specific number of function arguments? Even if I remove some arguments to avoid the segfault, still the output is wrong the second time.</p>
  
  <p>Some information about my environment:</p>
  
  <ul>
  <li>OS: (as given by <code>uname -a</code>) Linux lexdeb 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt25-2+deb8u3 (2016-07-02) x86_64 GNU/Linux (lexdeb is just the hostname)</li>
  <li>gcc version 4.9.2 (Debian 4.9.2-10)</li>
  <li>the program is in main.c file</li>
  <li><a href="http://pastebin.com/raw/Fgn4iiDs" rel="nofollow">compilation log</a></li>
  </ul>