-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using snprintf
instead of sprintf
for filenames
#108
Comments
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 <#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: ***@***.*** ***@***.***> >
|
I'm currently using g++ 13.2.0. The same warnings appear for slightly older versions as well. Yes, we could certainly just use a compiler switch to ignore the warnings. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 usingsnprintf
instead. As a result, when compiling HYDRAD, there are lots of warnings like this: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.
The text was updated successfully, but these errors were encountered: