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

Corrects clang-tidy warnings from atomutilities cpp file #1365

Merged
merged 4 commits into from
Oct 10, 2023
Merged

Corrects clang-tidy warnings from atomutilities cpp file #1365

merged 4 commits into from
Oct 10, 2023

Conversation

Xav83
Copy link
Contributor

@Xav83 Xav83 commented Oct 10, 2023

Hi OpenChemistry devs 🙂

I am creating this Pull Request in relation with the issue #1346, in the context of Hacktoberfest 2023.
So, as mentioned in the title, this Pull Request corrects the warnings generated by clang-tidy in the file avogadro/core/atomutilities.cpp. I chose this file because the warnings seemed simple to fix 😄

PS: if you have some files where you think clearing the clang-tidy warnings would be important/necessary, I'll be happy to do it in another Pull Request 😉


Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.

Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
have the right to submit it under the open source license
indicated in the file; or

(b) The contribution is based upon previous work that, to the best
of my knowledge, is covered under an appropriate open source
license and I have the right under that license to submit that
work with modifications, whether created in whole or in part
by me, under the same open source license (unless I am
permitted to submit under a different license), as indicated
in the file; or

(c) The contribution was provided directly to me by some other
person who certified (a), (b) or (c) and I have not modified
it.

(d) I understand and agree that this project and the contribution
are public and that a record of the contribution (including all
personal information I submit with it, including my sign-off) is
maintained indefinitely and may be redistributed consistent with
this project or the open source license(s) involved.

@welcome
Copy link

welcome bot commented Oct 10, 2023

Thanks for opening this pull request! Please check out our contributing guidelines and check for the automated tests.

Xav83 added 4 commits October 10, 2023 10:22
…nt variables instead of macros:

avogadro/core/atomutilities.cpp:12:9: warning: macro 'M_TETRAHED' used to declare a constant; consider using a 'constexpr' constant [cppcoreguidelines-macro-usage]
        ^

Signed-off-by: Xav83 <[email protected]>
…pedef' for aliases:

/home/runner/work/avogadrolibs/avogadrolibs/avogadrolibs/avogadro/core/atomutilities.cpp:16:1: warning: use 'using' instead of 'typedef' [modernize-use-using]
typedef Array<Bond> NeighborListType;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
using NeighborListType = Array<Bond>

Signed-off-by: Xav83 <[email protected]>
…ed as const references to avoid unecessary copy initialization:

/home/runner/work/avogadrolibs/avogadrolibs/avogadrolibs/avogadro/core/atomutilities.cpp:78:13: warning: the variable 'bond1' is copy-constructed from a const reference but is only used as const reference; consider making it a const reference [performance-unnecessary-copy-initialization]
    Vector3 bond1 = allVectors[0];
            ^
    const  &
/home/runner/work/avogadrolibs/avogadrolibs/avogadrolibs/avogadro/core/atomutilities.cpp:150:13: warning: the variable 'bond1' is copy-constructed from a const reference but is only used as const reference; consider making it a const reference [performance-unnecessary-copy-initialization]
    Vector3 bond1 = allVectors[0];
            ^
    const  &
/home/runner/work/avogadrolibs/avogadrolibs/avogadrolibs/avogadro/core/atomutilities.cpp:151:13: warning: the variable 'bond2' is copy-constructed from a const reference but is only used as const reference; consider making it a const reference [performance-unnecessary-copy-initialization]
    Vector3 bond2 = allVectors[1];
            ^
    const  &
/home/runner/work/avogadrolibs/avogadrolibs/avogadrolibs/avogadro/core/atomutilities.cpp:173:13: warning: the variable 'bond1' is copy-constructed from a const reference but is only used as const reference; consider making it a const reference [performance-unnecessary-copy-initialization]
    Vector3 bond1 = allVectors[0];
            ^
    const  &
/home/runner/work/avogadrolibs/avogadrolibs/avogadrolibs/avogadro/core/atomutilities.cpp:174:13: warning: the variable 'bond2' is copy-constructed from a const reference but is only used as const reference; consider making it a const reference [performance-unnecessary-copy-initialization]
    Vector3 bond2 = allVectors[1];
            ^
    const  &
/home/runner/work/avogadrolibs/avogadrolibs/avogadrolibs/avogadro/core/atomutilities.cpp:175:13: warning: the variable 'bond3' is copy-constructed from a const reference but is only used as const reference; consider making it a const reference [performance-unnecessary-copy-initialization]
    Vector3 bond3 = allVectors[2];
            ^
    const  &

Signed-off-by: Xav83 <[email protected]>
…from 'std::size_t' to 'int':

/home/runner/work/avogadrolibs/avogadrolibs/avogadrolibs/avogadro/core/atomutilities.cpp:70:24: warning: narrowing conversion from 'std::vector::size_type' (aka 'unsigned long') to signed type 'int' is implementation-defined [bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions]
  int currentValence = allVectors.size();
                       ^

Signed-off-by: Xav83 <[email protected]>
@github-actions
Copy link
Contributor

Here are the build results
Avogadro2.AppImage
macOS.dmg
Win64.exe
Artifacts will only be retained for 90 days.

@ghutchis
Copy link
Member

Thanks! It's been a while since I've run clang-tidy (thus the PR). I wouldn't mind someone looking at avogadro/io/fileformat.cpp particularly line 37 / 47, which have been flagged for taking filenames from users. I guess these should be checked for path redirection, e.g. "..", etc.

If you can post the clang-tidy warnings somewhere, I'd be happy to take a look and suggest some other files / warnings to target.

@ghutchis ghutchis merged commit 7f27522 into OpenChemistry:master Oct 10, 2023
@welcome
Copy link

welcome bot commented Oct 10, 2023

Congrats on merging your first pull request! 🎉 Thanks for making Avogadro better for everyone!

@github-actions
Copy link
Contributor

Here are the build results
Avogadro2.AppImage
macOS.dmg
Win64.exe
Artifacts will only be retained for 90 days.

@Xav83
Copy link
Contributor Author

Xav83 commented Oct 10, 2023

@ghutchis Here is the log file from clang-tidy analysis: 11_Analyze.txt (this is the analysis generated before the integration of this PR).

There is no warning found by clang-tidy about the file avogadro/io/fileformat.cpp, so no help from this tool.
In C++17, I know there are the functions std::filesystem::canonical, std::filesystem::weakly_canonical that could help you get rid of the redirections. But I have to admit that I have never really experimented with them 😄.

@ghutchis
Copy link
Member

Thanks for the log.

Yes, I'm putting together a separate PR on filenames. It's not perfect, but it at least performs some checks.

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

Successfully merging this pull request may close these issues.

2 participants