[ET Trac] #2749: WVUThorns: sprintf use violates standard
Erik Schnetter
trac-noreply at einsteintoolkit.org
Wed Aug 23 14:23:44 CDT 2023
#2749: WVUThorns: sprintf use violates standard
Reporter: Erik Schnetter
Status: new
Milestone:
Version:
Type: bug
Priority: minor
Component: EinsteinToolkit thorn
I see these warnings when building WVUThorns:
```
/Users/eschnett/Cactus/arrangements/WVUThorns_Diagnostics/particle_tracerET/src/file_output_routines.C: In function 'void particle_tracerET_file_output_ascii(cGH*)':
/Users/eschnett/Cactus/arrangements/WVUThorns_Diagnostics/particle_tracerET/src/file_output_routines.C:143:14: warning: 'sprintf' argument 3 overlaps destination object 'buffer' [-Wrestrict]
143 | sprintf(buffer, "%s %e %e %e %e", buffer, particle_u4U0[which_particle], particle_u4U1[which_particle], particle_u4U2[which_particle], particle_u4U3[which_particle]);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/eschnett/Cactus/arrangements/WVUThorns_Diagnostics/particle_tracerET/src/file_output_routines.C:154:14: warning: 'sprintf' argument 3 overlaps destination object 'buffer' [-Wrestrict]
154 | sprintf(buffer, "%s %e %e %e %e", buffer, particle_u4D0[which_particle], particle_u4D1[which_particle], particle_u4D2[which_particle], particle_u4D3[which_particle]);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/eschnett/Cactus/arrangements/WVUThorns_Diagnostics/particle_tracerET/src/file_output_routines.C:132:12: warning: 'sprintf' argument 3 overlaps destination object 'buffer' [-Wrestrict]
132 | sprintf(buffer, "%s %e %e %e", buffer, particle_position_x[which_particle], particle_position_y[which_particle], particle_position_z[which_particle]);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
COMPILING WVUThorns_Diagnostics/particle_tracerET/src/Interpolate_velocities_at_particle_positions.C
```
The C/C\+\+ standards do not allow writing the buffer to itself \(although this is a convenient way to append to a string\).
Since this is C\+\+ code I suggest to use `std::ostringstream` instead.
--
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/20230823/83e9489a/attachment.htm>
More information about the Trac
mailing list