[ET Trac] #2749: WVUThorns: sprintf use violates standard

Roland Haas trac-noreply at einsteintoolkit.org
Thu Aug 24 13:24:10 CDT 2023


#2749: WVUThorns: sprintf use violates standard

 Reporter: Erik Schnetter
   Status: new
Milestone: 
  Version: 
     Type: bug
 Priority: minor
Component: EinsteinToolkit thorn

Comment (by Roland Haas):

alternatively \(if one needs control over formatting\) one can use something like:

```
snprintf(buffer+strlen(buffer), sizeof(buffer) - strlen(buffer), "...",  particle_u4U0[which_particle])
```

where one leaves out the first “buffer” \(and its “%s”\).

Alternatively, if this, as I suspect, is written to a file anyway, just use multiple `fprintf` 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\).

--
Ticket URL: https://bitbucket.org/einsteintoolkit/tickets/issues/2749/wvuthorns-sprintf-use-violates-standard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.einsteintoolkit.org/pipermail/trac/attachments/20230824/5eeab137/attachment-0001.htm>


More information about the Trac mailing list