-
Notifications
You must be signed in to change notification settings - Fork 6
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
C++ siteupdate: Use of sprintf, deprecated on MacOS/XCode #585
Comments
I'll hazard a guess that these use std::string. I'm ambivalent toward std::string (vice C strings); on the one hand, it's great for permanent storage of text, or reading in new data when I don't know how much storage space I'll need. Calling
This suggests to me this may be an Apple-specific thing (*glares at Apple*), although, clang 14 vs 13 on noreaster... wonder if this may show up on Unix-Unix boxes with new clang versions in the future? Meh. Consarnit, I'm trying to be a cowboy here, and Apple's excessive hand-holding ain't helping! 🤣 Rather than just a blanket SPRINTF BAD deprecation of the function, I'd even prefer GCC's approach of heuristically determining if an overflow will be likely, like what happened with 58b4b57. char fstr[44];
sprintf(fstr, "(%.15g,%.15g)", w->lat, w->lng); One byte has to be the null terminator, so that leaves us 43 B useful buffer space. I see 2 ways to quiet XCode down:
So I'll gladly accept @jteresco's |
fprintf may be able to get rid of most The downside is that it uses C's FILE rather than C++'s std::ofstream, so it'd involve a little reinvention of the wheel. |
Great news:sprintf is a performance killer. Yes, this is great news. Most uses format a string and immediately plop it into a file. I'm not going to look into fprintf as it surely has to suffer from the same drawbacks as sprintf, having to parse a format string.
ToDo:
The remaining uses do use the results for string manipulation, not just writing to a file. These cases are infrequent enough that I can just accept using
I'm going to hold off on a pull request for this for a wee bit. |
When compiling on MacOS, the C++ site update code generates pages of warnings:
I'm ok leaving it or replacing our
sprintf
calls withsnprintf
calls. A little of what I saw when searching around on this is that there are also some more C++-specific ways to achieve the same result.Compiler version:
The text was updated successfully, but these errors were encountered: