by Chris » Thu Dec 14, 2023 6:33 pm
dpJudas wrote: ↑Thu Dec 14, 2023 3:23 am
All software on the planet contains bugs and no amount of linters is ever going to change that.
Of course. No one's arguing this makes the code bug-free, but it does demonstrably reduce the amount and severity of bugs.
dpJudas wrote: ↑Thu Dec 14, 2023 3:23 am
The point I'm making with this is that there are theoretical bugs and then there's the bugs that users actually encounter. The linter helped you against the theoretical ones and its only happenstance whenever it finds any in the second category.
All bugs are theoretical until they happen. It's a question of the likelihood that the code will trigger a specific one (and unless we solve the halting problem, we can never be sure it will or won't; so you either assume it won't and don't warn, or assume it can and warn). At least with clang-tidy, you can control what it warns about, with the default being relatively conservative. I think the only issues it brought up when I first tried on all of OpenAL Soft it was complaining that
memmove was unsafe (4 uses in examples written in C), use
memmove_s instead. It wasn't until I enabled the
modernize-* set that it really started complaining, the primary one being using trailing return types. I went to myself, "as much as I'd like/prefer trailing return types, there's just too many functions to change for no direct benefit", then disabled
modernize-use-trailing-return-type and those warnings went away. Maybe one day if I'm bored with extra time I may chip away at it, but as it is, out of sight out of mind.
dpJudas wrote: ↑Thu Dec 14, 2023 3:23 am
All I'm saying is that the signal to noise ratio isn't worth it for me.
I'm not suggesting that all warnings should be enabled always. With OpenAL Soft, which is a much smaller and newer codebase, I'm still starting with clang-tidy using a very conservative default and incrementally enabling certain warnings because there'd be too much at once otherwise. And I don't foresee myself going beyond
modernize-* and
cppcoreguidelines-*, which is only a fraction of the total warnings that can be enabled, and even of those I'll probably be leaving some off.
dpJudas wrote: ↑Thu Dec 14, 2023 3:23 am
These so-called experts that think you can secure C++ using guidelines and best practices are completely delusional.
I don't think anyone is under the delusion that simply having guidelines and best practices will "secure" C++. What's needed is enforcement of those guidelines (as you say below; it's all well and good to have guidelines say "don't use unions, use a variant", but unless a union causes an error, people will still use it), and that's where the tricky part is since you have issues of compatibility.
dpJudas wrote: ↑Thu Dec 14, 2023 3:23 am
If your software require this level of security then don't use C++ for it.
It's not just security, but also stability and safety. GZDoom writing past the end of a buffer isn't going to cause a sensitive data leak for millions of people, no, but it would still be nice to prevent it from writing to random memory and cause hard-to-track crashes or misbehaviors (or worse, have some enterprising modders realize that with specially-crafted data, it can create a buffer overflow that can cause funky effects and make a popular mod out of it, that will inevitably stop working and create unhappy users who don't want to update; or have a mod cause arbitrary code execution from a buffer overflow, infect the system with a virus).
dpJudas wrote: ↑Thu Dec 14, 2023 3:23 am
You have to
block all the ways you can do out of bounds stuff in the language to even begin to claim you are secure like this. 40 years of C++ has consistently proven that no human being on the planet is actually good enough, even when trying to be as disciplined as possible, to prevent this kind of thing.
Mathematically making something impossible is always infinitely better than anything else. That's why we use unique/shared pointer and move semantics to prevent memory leaks. No linter ever was able to stop people from fucking up their new and delete statements. No guides did the trick either.
It is possible to hook linters (at least clang-tidy) up to your build system and have them cause a build failure if their checks fail, with either a select set of checks for the whole project (easiest for a new project), or specific per-file checks (if you want to incrementally add checks to an existing codebase). There are also interesting projects like Cppfront/Cpp2, that allows for writing in a new safer syntax that gets appropriate checks/restrictions, and optionally allows interleaving with standard C++ code, which it remains fully interoperable with (you can switch any C++ project to use cppfront and it will work as-is with no changes, but you can then write a function with the new "Cpp2" syntax, and that function gets improved defaults, checks, and restrictions). I think it's kind of interesting
[1] [2].
[quote=dpJudas post_id=1248336 time=1702545793 user_id=18514]
All software on the planet contains bugs and no amount of linters is ever going to change that.
[/quote]
Of course. No one's arguing this makes the code bug-free, but it does demonstrably reduce the amount and severity of bugs.
[quote=dpJudas post_id=1248336 time=1702545793 user_id=18514]
The point I'm making with this is that there are theoretical bugs and then there's the bugs that users actually encounter. The linter helped you against the theoretical ones and its only happenstance whenever it finds any in the second category.
[/quote]
All bugs are theoretical until they happen. It's a question of the likelihood that the code will trigger a specific one (and unless we solve the halting problem, we can never be sure it will or won't; so you either assume it won't and don't warn, or assume it can and warn). At least with clang-tidy, you can control what it warns about, with the default being relatively conservative. I think the only issues it brought up when I first tried on all of OpenAL Soft it was complaining that [c]memmove[/c] was unsafe (4 uses in examples written in C), use [c]memmove_s[/c] instead. It wasn't until I enabled the [c]modernize-*[/c] set that it really started complaining, the primary one being using trailing return types. I went to myself, "as much as I'd like/prefer trailing return types, there's just too many functions to change for no direct benefit", then disabled [c]modernize-use-trailing-return-type[/c] and those warnings went away. Maybe one day if I'm bored with extra time I may chip away at it, but as it is, out of sight out of mind.
[quote=dpJudas post_id=1248336 time=1702545793 user_id=18514]
All I'm saying is that the signal to noise ratio isn't worth it for me.
[/quote]
I'm not suggesting that all warnings should be enabled always. With OpenAL Soft, which is a much smaller and newer codebase, I'm still starting with clang-tidy using a very conservative default and incrementally enabling certain warnings because there'd be too much at once otherwise. And I don't foresee myself going beyond [c]modernize-*[/c] and [c]cppcoreguidelines-*[/c], which is only a fraction of the total warnings that can be enabled, and even of those I'll probably be leaving some off.
[quote=dpJudas post_id=1248336 time=1702545793 user_id=18514]
These so-called experts that think you can secure C++ using guidelines and best practices are completely delusional.
[/quote]
I don't think anyone is under the delusion that simply having guidelines and best practices will "secure" C++. What's needed is enforcement of those guidelines (as you say below; it's all well and good to have guidelines say "don't use unions, use a variant", but unless a union causes an error, people will still use it), and that's where the tricky part is since you have issues of compatibility.
[quote=dpJudas post_id=1248336 time=1702545793 user_id=18514]
If your software require this level of security then don't use C++ for it.
[/quote]
It's not just security, but also stability and safety. GZDoom writing past the end of a buffer isn't going to cause a sensitive data leak for millions of people, no, but it would still be nice to prevent it from writing to random memory and cause hard-to-track crashes or misbehaviors (or worse, have some enterprising modders realize that with specially-crafted data, it can create a buffer overflow that can cause funky effects and make a popular mod out of it, that will inevitably stop working and create unhappy users who don't want to update; or have a mod cause arbitrary code execution from a buffer overflow, infect the system with a virus).
[quote=dpJudas post_id=1248336 time=1702545793 user_id=18514]
You have to [i]block[/i] all the ways you can do out of bounds stuff in the language to even begin to claim you are secure like this. 40 years of C++ has consistently proven that no human being on the planet is actually good enough, even when trying to be as disciplined as possible, to prevent this kind of thing. [i]Mathematically[/i] making something impossible is always infinitely better than anything else. That's why we use unique/shared pointer and move semantics to prevent memory leaks. No linter ever was able to stop people from fucking up their new and delete statements. No guides did the trick either.
[/quote]
It is possible to hook linters (at least clang-tidy) up to your build system and have them cause a build failure if their checks fail, with either a select set of checks for the whole project (easiest for a new project), or specific per-file checks (if you want to incrementally add checks to an existing codebase). There are also interesting projects like Cppfront/Cpp2, that allows for writing in a new safer syntax that gets appropriate checks/restrictions, and optionally allows interleaving with standard C++ code, which it remains fully interoperable with (you can switch any C++ project to use cppfront and it will work as-is with no changes, but you can then write a function with the new "Cpp2" syntax, and that function gets improved defaults, checks, and restrictions). I think it's kind of interesting [url=https://www.youtube.com/watch?v=ELeZAKCN4tY][1][/url] [url=https://www.youtube.com/watch?v=fJvPBHErF2U][2][/url].