What can happen if printf is called with a wrong format string?
<p>Or in other words: Could a wrong <code>printf</code> / <code>fprintf</code> decimal integer (<code>%d</code>, <code>%u</code>, <code>%ld</code>, <code>%lld</code>) format string cause a program to crash or lead to undefined behavior?</p>

<p>Cosinder following lines of code:</p>

<pre class="lang-cpp prettyprint-override"><code>#include &lt;iostream&gt;
#include &lt;cstdio&gt;

int main() {
    std::cout &lt;&lt; sizeof(int) &lt;&lt; std::endl
              &lt;&lt; sizeof(long) &lt;&lt; std::endl;

    long a = 10;
    long b = 20;
    std::printf("%d, %d\n", a, b);

    return 0;
}
</code></pre>

<p>Result on 32 bit architecture:</p>

<pre><code>4
4
10, 20
</code></pre>

<p>Result on 64 bit architecture:</p>

<pre><code>4
8
10, 20
</code></pre>

<p>In any case the program prints the expected result. I know, if the <code>long</code> value exceeds the <code>int</code> range, the program prints wrong numbers – which is ugly, but doesn't effect the main purpose of the program –, but beside this, could anything unexpected happen?</p>
