rice-solar-physics / HYDRAD

HYDrodynamics and RADiation Code for computing solutions to field-aligned hydrodynamic equations in coronal loops
MIT License
10 stars 5 forks source link

Using `snprintf` instead of `sprintf` for filenames #108

Open jwreep opened 1 day ago

jwreep commented 1 day ago

This is relatively minor, but it clutters the compiler output. Recent C++ versions are now returning warnings for sprintf, which can lead to memory leaks, and recommend using snprintf instead. As a result, when compiling HYDRAD, there are lots of warnings like this:

WARNING: ../source/mesh.cpp:1866:1: warning: 'sprintf' is deprecated: This function is provided for compatibility reasons only.  
Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead. 
[-Wdeprecated-declarations]
sprintf( szPhysicalFilename, "Results/profile%i.phy", iFileNumber );

The code doesn't have any memory leaks from what I can tell, but it would be nice to clear away these warnings at some point.

sjbradshaw commented 1 day ago

There’s probably a compiler flag to switch off this particular warning if it gets annoying. Something like:

-Wignore-annoying-sprintf-warning

Which c++ compiler / version are you using to build it now?

From: Jeffrey Reep @.> Sent: Friday, October 18, 2024 4:33 PM To: rice-solar-physics/HYDRAD @.> Cc: Subscribed @.***> Subject: [rice-solar-physics/HYDRAD] Using snprintf instead of sprintf for filenames (Issue #108)

This is relatively minor, but it clutters the compiler output. Recent C++ versions are now returning warnings for sprintf, which can lead to memory leaks, and recommend using https://cplusplus.com/reference/cstdio/snprintf/ snprintf instead. As a result, when compiling HYDRAD, there are lots of warnings like this:

WARNING: ../source/mesh.cpp:1866:1: warning: 'sprintf' is deprecated: This function is provided for compatibility reasons only.
Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead. [-Wdeprecated-declarations] sprintf( szPhysicalFilename, "Results/profile%i.phy", iFileNumber );

The code doesn't have any memory leaks from what I can tell, but it would be nice to clear away these warnings at some point.

— Reply to this email directly, view it on GitHub https://github.com/rice-solar-physics/HYDRAD/issues/108 , or unsubscribe https://github.com/notifications/unsubscribe-auth/ACC6C7V3GFSWJ5RYKNUR4F3Z4F5AFAVCNFSM6AAAAABQGXUAUCVHI2DSMVQWIX3LMV43ASLTON2WKOZSGU4TQNBSGE2TMMI . You are receiving this because you are subscribed to this thread. https://github.com/notifications/beacon/ACC6C7S2VLEGRHWP3ICK763Z4F5AFA5CNFSM6AAAAABQGXUAUCWGG33NNVSW45C7OR4XAZNFJFZXG5LFVJRW63LNMVXHIX3JMTHJVYGEHE.gif Message ID: @. @.> >