Skip to content
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

Fixed most all of the reasonable clang-tidy warnings #1479

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

seanm
Copy link
Contributor

@seanm seanm commented Apr 9, 2024

No description provided.

else if (r != 4 || str.desc.bLength < 4)
return LIBUSB_ERROR_IO;
else if (str.desc.bDescriptorType != LIBUSB_DT_STRING)
else if (r != 4 || str.desc.bLength < 4 || str.desc.bDescriptorType != LIBUSB_DT_STRING)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what was the warning here?
I personally find the "before" more descriptive/readable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else if (r < DESC_HEADER_LENGTH || str.desc.bLength > r)
return LIBUSB_ERROR_IO;
else if (str.desc.bDescriptorType != LIBUSB_DT_STRING)
else if (r < DESC_HEADER_LENGTH || str.desc.bLength > r || str.desc.bDescriptorType != LIBUSB_DT_STRING)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

@mcuee mcuee added the enhancement New features label Apr 11, 2024
@tormodvolden
Copy link
Contributor

I appreciate the systematic approach, and I understand the motivation to silence clang-tidy, but I would prefer the commit summary to say what change is done*, or how it makes the code better, independent of clang-tidy. Silencing clang-tidy is of course a nice side-effect :) And it is important to note if some commits only affects examples or some platform, it makes it much easier for someone to peruse the git log and skip things that are not of their interest. If small trivial fixes to an example file can be grouped together that is fine too.

*) Generally it should express the intention do something, not what one thinks has been done. It is not always the same :)

E.g.:
<- Fixed all clang-tidy bugprone-unsafe-functions warnings
<- Replaced rewind, which gives no error result, with fseek, which does.

-> examples/ezusb: Replace rewind, which gives no error result, with fseek, which does
-> This fixes the last clang-tidy bugprone-unsafe-functions warning.

@seanm
Copy link
Contributor Author

seanm commented May 7, 2024

...I would prefer the commit summary to say what change is done...

Some of them do, but yeah ok I'll improve all the commit messages with more detail.

@tormodvolden
Copy link
Contributor

All the summaries (first line) say "Fixed all clang-tidy...".

@seanm
Copy link
Contributor Author

seanm commented May 7, 2024

All the summaries (first line) say "Fixed all clang-tidy...".

Oh missed that, it's the summaries you don't like... I guess I'm so familiar with their names that it seems clear to me. I'll reword them...

@tormodvolden
Copy link
Contributor

All the summaries (first line) say "Fixed all clang-tidy...".

Oh missed that, it's the summaries you don't like... I guess I'm so familiar with their names that it seems clear to me. I'll reword them...

No, you don't need to reword the names of the clang-tidy keywords if that is what you mean. But they should be relegated to the message, not the summary. Please see my example above.

@seanm
Copy link
Contributor Author

seanm commented May 8, 2024

OK done, hopefully you like it better now.

@seanm
Copy link
Contributor Author

seanm commented May 27, 2024

I added those prefix things you like

seanm added 13 commits May 29, 2024 14:06
…ich does.

Fixes all clang-tidy bugprone-unsafe-functions warnings
The C langugage reserves various identifiers for itself that user code must not use.

Fixes all clang-tidy bugprone-reserved-identifier warnings

Also, 4 of 5 file extension tests were case insensitive, and 1 was not. Changed it to be insensitive too.
…any lower-precedence operators from the surrounding expression

Fixes all clang-tidy bugprone-macro-parentheses warnings
Took the name from the .c file.

Fixes all clang-tidy readability-inconsistent-declaration-parameter-name warnings
All such warnings are already fixed in master.
Depending on the font, an l suffix can look like a 1. Consider "231l". Thus prefer uppercase.

Fixes all clang-tidy readability-uppercase-literal-suffix warnings
Fixes all clang-tidy bugprone-assignment-in-if-condition warnings
Copy-pasting can often result in mistakes like:

```
if (test_value(x)) {
  y++;
  do_something(x, y);
} else {
  y++;
  do_something(x, y);
}
```

Thus it is preferable that branch bodies be unique.

Fixes all clang-tidy bugprone-branch-clone warnings
…or 1

Fixes all clang-tidy bugprone-suspicious-string-compare warnings
Fixes all clang-tidy readability-non-const-parameter warnings
These multiplication could indeed have overflowed, but now they are performed with a bigger type, matching the type they are ultimately stored in.

Fixes all clang-tidy bugprone-implicit-widening-of-multiplication-result warnings
…iterated

Fixes all clang-tidy bugprone-too-small-loop-variable warnings
The addition could overflow, the upcast needs to be performed before, not after.

Fixes all clang-tidy bugprone-misplaced-widening-cast warnings
@seanm
Copy link
Contributor Author

seanm commented May 30, 2024

@tormodvolden hopefully we can get this one merged next?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants