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

clang-tidy and manual stuff #2177

Merged
merged 13 commits into from
Apr 6, 2022
Merged

clang-tidy and manual stuff #2177

merged 13 commits into from
Apr 6, 2022

Conversation

neheb
Copy link
Collaborator

@neheb neheb commented Mar 31, 2022

No description provided.

@codecov
Copy link

codecov bot commented Mar 31, 2022

Codecov Report

Merging #2177 (262d0ee) into main (74622cf) will decrease coverage by 0.01%.
The diff coverage is 62.29%.

@@            Coverage Diff             @@
##             main    #2177      +/-   ##
==========================================
- Coverage   63.30%   63.29%   -0.02%     
==========================================
  Files          99       99              
  Lines       19596    19591       -5     
  Branches     9559     9556       -3     
==========================================
- Hits        12406    12400       -6     
- Misses       5116     5117       +1     
  Partials     2074     2074              
Impacted Files Coverage Δ
src/convert.cpp 51.47% <ø> (ø)
src/crwimage_int.hpp 92.85% <ø> (ø)
src/error.cpp 83.60% <ø> (-0.27%) ⬇️
src/exif.cpp 65.91% <ø> (ø)
src/http.cpp 0.00% <0.00%> (ø)
src/pgfimage.cpp 42.76% <0.00%> (ø)
src/tags.cpp 67.24% <ø> (ø)
src/cr2image.cpp 19.48% <9.09%> (ø)
src/basicio.cpp 51.44% <50.00%> (ø)
src/tags_int.hpp 86.04% <85.71%> (ø)
... and 11 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b8cb4e0...262d0ee. Read the comment docs.

src/types.cpp Outdated Show resolved Hide resolved
Comment on lines +846 to 847
auto wrote = static_cast<size_t>(snprintf(temp, sizeof(temp), "%04d%02d%02d", date_.year, date_.month, date_.day));
std::memcpy(buf, temp, wrote);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
auto wrote = static_cast<size_t>(snprintf(temp, sizeof(temp), "%04d%02d%02d", date_.year, date_.month, date_.day));
std::memcpy(buf, temp, wrote);
auto wrote = snprintf(temp, sizeof(temp), "%04d%02d%02d", date_.year, date_.month, date_.day);
assert(wrote >= 0);
std::memcpy(buf, temp, static_cast<size_t>(wrote));

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That makes no sense. The function returns size_t.

Copy link
Collaborator

Choose a reason for hiding this comment

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

That's incorrect:

https://en.cppreference.com/w/c/io/fprintf

snprintf returns int, and it sometimes returns negative numbers on error. I don't think it will ever return a negative number here though, which is why I think an assert is sufficient, rather throwing an exception.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I also noticed that snprintf returns int but I thought it would not ever happen in this case. We recently removed most (if not all) the asserts from the codebase since those only get executed in Debug builds.

For me the code it is fine as it is at the moment. At the end we need to place 1 static_assert somewhere and I do not see any advantage with having it in the call to snprintf compared to doing it later (line 848).

I am approving the PR but not merging it yet. @kevinbackhouse let us know if you really think there is a strong reason/advantage to choose your suggestion.

@neheb
Copy link
Collaborator Author

neheb commented Mar 31, 2022

Removed last commit.

neheb added 10 commits April 1, 2022 16:37
Signed-off-by: Rosen Penev <[email protected]>
Signed-off-by: Rosen Penev <[email protected]>
Signed-off-by: Rosen Penev <[email protected]>
Signed-off-by: Rosen Penev <[email protected]>
Signed-off-by: Rosen Penev <[email protected]>
Signed-off-by: Rosen Penev <[email protected]>
Signed-off-by: Rosen Penev <[email protected]>
Found with google-build-using-namespace

Signed-off-by: Rosen Penev <[email protected]>
@@ -41,13 +43,6 @@ using DWORD = unsigned long;
static int WSAGetLastError() {
return errno;
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

Comment on lines +846 to 847
auto wrote = static_cast<size_t>(snprintf(temp, sizeof(temp), "%04d%02d%02d", date_.year, date_.month, date_.day));
std::memcpy(buf, temp, wrote);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I also noticed that snprintf returns int but I thought it would not ever happen in this case. We recently removed most (if not all) the asserts from the codebase since those only get executed in Debug builds.

For me the code it is fine as it is at the moment. At the end we need to place 1 static_assert somewhere and I do not see any advantage with having it in the call to snprintf compared to doing it later (line 848).

I am approving the PR but not merging it yet. @kevinbackhouse let us know if you really think there is a strong reason/advantage to choose your suggestion.

@piponazo piponazo merged commit 6e9eca4 into Exiv2:main Apr 6, 2022
@neheb neheb deleted the 1 branch April 6, 2022 12:56
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.

3 participants