<html>#2749: WVUThorns: sprintf use violates standard
<table style='border-spacing: 1ex 0pt; '>
<tr><td style='text-align:right'> Reporter:</td><td>Erik Schnetter</td></tr>
<tr><td style='text-align:right'>   Status:</td><td>new</td></tr>
<tr><td style='text-align:right'>Milestone:</td><td></td></tr>
<tr><td style='text-align:right'>  Version:</td><td></td></tr>
<tr><td style='text-align:right'>     Type:</td><td>bug</td></tr>
<tr><td style='text-align:right'> Priority:</td><td>minor</td></tr>
<tr><td style='text-align:right'>Component:</td><td>EinsteinToolkit thorn</td></tr>
</table>

<p>Comment (by Roland Haas):</p>
<p>alternatively (if one needs control over formatting) one can use something like:</p>
<div class="codehilite"><pre><span></span><span class="n">snprintf</span><span class="p">(</span><span class="n">buffer</span><span class="o">+</span><span class="n">strlen</span><span class="p">(</span><span class="n">buffer</span><span class="p">),</span><span class="w"> </span><span class="n">sizeof</span><span class="p">(</span><span class="n">buffer</span><span class="p">)</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="n">strlen</span><span class="p">(</span><span class="n">buffer</span><span class="p">),</span><span class="w"> </span><span class="ss">"..."</span><span class="p">,</span><span class="w">  </span><span class="n">particle_u4U0</span><span class="o">[</span><span class="n">which_particle</span><span class="o">]</span><span class="p">)</span><span class="w"></span>
</pre></div>


<p>where one leaves out the first “buffer” (and its “%s”).</p>
<p>Alternatively, if this, as I suspect, is written to a file anyway, just use multiple <code>fprintf</code> calls which do use buffering anyway so will typically only write (to a file) in 1k or so chunks. If this is ASCII file IO, then any optimization on the code part is premature anyway since IO (and the binary to ASCII conversion) will be the slow parts anyway (well unless one plasters the code with many many malloc/new/string/osstream object creations that is).</p>
<p>--<br/>
Ticket URL: <a href='https://bitbucket.org/einsteintoolkit/tickets/issues/2749/wvuthorns-sprintf-use-violates-standard'>https://bitbucket.org/einsteintoolkit/tickets/issues/2749/wvuthorns-sprintf-use-violates-standard</a></p>
</html>