Skip to content

[C++] Fix unsigned integer check in Solution.h#1850

Merged
ischoegl merged 2 commits intoCantera:mainfrom
g3bk47:patch-8
Feb 5, 2025
Merged

[C++] Fix unsigned integer check in Solution.h#1850
ischoegl merged 2 commits intoCantera:mainfrom
g3bk47:patch-8

Conversation

@g3bk47
Copy link
Copy Markdown
Contributor

@g3bk47 g3bk47 commented Feb 4, 2025

Changes proposed in this pull request

Remove check for negative index value and use the IndexError exception type in Solution.h.

Closes #1849.

Before merging the PR: Is m_adjacent guaranteed to have at least one element? Otherwise, the maximum allowed index (last parameter in IndexError's constructor) should probably be handled differently for m_adjacent.size() == 0.

Checklist

  • The pull request includes a clear description of this code change
  • Commit messages have short titles and reference relevant issues
  • Build passes (scons build & scons test) and unit tests address code coverage
  • Style & formatting of contributed code follows contributing guidelines
  • The pull request is ready for review

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 4, 2025

Codecov Report

Attention: Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.

Project coverage is 74.40%. Comparing base (e6f3e9d) to head (f4cde59).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
include/cantera/base/Solution.h 0.00% 1 Missing and 1 partial ⚠️
src/base/ctexceptions.cpp 0.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1850      +/-   ##
==========================================
- Coverage   74.41%   74.40%   -0.01%     
==========================================
  Files         386      386              
  Lines       53628    53630       +2     
  Branches     9063     9064       +1     
==========================================
  Hits        39905    39905              
- Misses      10652    10653       +1     
- Partials     3071     3072       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ischoegl
Copy link
Copy Markdown
Member

ischoegl commented Feb 5, 2025

@g3bk47 ... thanks for the PR!

Before merging the PR: Is m_adjacent guaranteed to have at least one element? Otherwise, the maximum allowed index (last parameter in IndexError's constructor) should probably be handled differently for m_adjacent.size() == 0.

No: it is not guaranteed to have at least one element. Indeed, it will have zero entries in most cases. As this case isn't adequately covered in IndexError, it may be best to address it there.

@g3bk47
Copy link
Copy Markdown
Contributor Author

g3bk47 commented Feb 5, 2025

@ischoegl I extended IndexError's logic to check for empty arrays. Since size-1 will be npos for size==0, I think the current PR handles all current uses of IndexError without introducing too much additional code.

Copy link
Copy Markdown
Member

@ischoegl ischoegl left a comment

Choose a reason for hiding this comment

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

Thanks, @g3bk47, this looks good to me!

@ischoegl ischoegl merged commit fd1a410 into Cantera:main Feb 5, 2025
47 of 49 checks passed
@ischoegl ischoegl mentioned this pull request Feb 6, 2025
5 tasks
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.

Unsigned integer checked for negative values in Solution.h

2 participants