-
Notifications
You must be signed in to change notification settings - Fork 88
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
Discovered a lot of minor problems after running static code analysis #33
Comments
I sometimes write similar code to this. The point for me is that even though the if is always false now, you never know how the code will change later and suddenly the frame csrc can be invalid. This makes the code less prone to have bugs. This code could use more debug prints though to indicate that something went wrong and still work. This way it does not immediately become show stopper while alerting the dev that there is a problem. This is just my way of coding things and I'm not sure if @altonen had the same idea or what. I'm not sure all of the if:s are needed, but hard to say without specific list. The middle one seems unnecessary to me. Which analysis tool did you use? Can you paste the output? |
I expect you refer to the third example ? Not sure what you mean by "invalid". It is totally save to delete an nullptr, so there would be no need to check for it.
I've used just the integration in Clion which uses Clang-tidy. I cannot paste the output, that would be way to much and not everything is really sensible. But I could embed a analyzing target into the CMake file. |
I've been thinking about this and maybe what I meant was that checking pointers and values that come from outside the function is important, but if the value is set inside the same function then I see no sense in checking it. I'm not very familiar on what types of issues the code analyzer recognizes. I have seen a lot of the C way, where variables are created at the start of the function, whereas I like to create them as close to their usage as possible (and initialize them for sure). This might be part of the problem and would like it changed at some point. I would also like @altonen's opinion on the purpose of these checks. |
The first example I don't understand. I took a quick look at the code and I see that The second code example is a result of some refactoring, the second check for I have no recollection of writing that CSRC check code so I cannot comment on why the value is checked before it's released. But it can be removed of course. |
This is because in the file |
@db-tech you can make a PR if you want. If there are some checks that seem like they should be there, I can add them back afterwards. It doesn't sound like there would be many if any. Seems like this invalid intra is a separate issue. |
K, I will create a PR as soon as I find the time. |
There are a lot of function with double underscore in the name, the standard states:
I am, personally not fond of them either :-) |
Sorry, I have to give up. It is just to much stuff that I cannot simply change without asking you first. I would suggest that you do some static code analysis yourself and go over file by file to change the problems in one big sweep. I could offer you a pair programming session where we discuss some stuff live. |
Understandable. I realized that I have been naturally running IntelliSense with msvc compilations. I also tried Clang-tidy through Qt Creator which gives slightly different results. I have gotten a lot of warnings that I think should be addressed (I already tried addressing type conversions), but not these ones mentioned in this issue. Qt creator does offers more options for tidy that can be enabled so maybe that is the reason. I think prefix underscores should definitely be removed. They seem to exist with local functions, so maybe an underscore afterwards or adding word local to function beginning would be a good alternative. I'm new to this project as well, so it will take some time to establish a new style guide (with c++ stuff and more secure code base). I will create a new issue when I start working on this and will warmly welcome everyone to participate in the discussion. Some sort of meeting or two could be organized once the first draft has been formulated. Adding analysis into CMake file would not be a bad idea. |
I removed most compiler warnings on MSVC (expect class enum) and all warnings on Linux. I also run the Clang static analyzer and fixed issues it pointed out in its report. I'm not super experienced with static analyzers, but I fixed all warnings I could get my hands on, so I will consider this issue solved. If there is a specific tool that should be run, anyone can suggest it by opening a new issue. |
I did check the source with a static code analyzer and found lots of maybe minor problems that should be resolved.
Just to show some examples
condition is always false
unreachable code
Also there are a lot of those checks:
It by no means critical, but could be changed easily and therefore make it more readable.
Those are just examples, there is a lot more stuff.
I guess those could be done in one bigger PR...
The text was updated successfully, but these errors were encountered: