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

Handle non-existent module filename extension reliably #543

Merged
merged 1 commit into from
Jun 23, 2023

Conversation

mattw-nws
Copy link
Contributor

@mattw-nws mattw-nws commented Jun 23, 2023

Ensures that the substr call does not get a parameter that is larger than the string length if there is no extension in the bmi_lib_file string.

Using the "extensionless" filename for a shared library in a realization config is supposed to work, with ngen attaching whatever extension is typical for the OS. However, the code for doing that does not handle the case correctly. The docs say that std::string's rfind method returns string::npos when the string is not found, and that string::npos is -1 ... but the type is unsigned... so it is the max size_t value. This apparently causes the calls to .substr below to blow up. But... this was working previously, so must be a victim of undefined behavior--despite the fact that the docs for substr say that this should cause out_of_range to be thrown.

Puzzling. See also ca76cc6 and f64ffd3 ... so this has worked in the past as it was.

Additions

Removals

Changes

  • Added check for string::npos in return of rfind

Testing

Screenshots

image

Notes

Todos

Checklist

  • PR has an informative and human-readable title
  • Changes are limited to a single goal (no scope creep)
  • Code can be automatically merged (no conflicts)
  • Code follows project standards (link if applicable)
  • Passes all existing automated tests
  • Any change in functionality is tested
  • New functions are documented (with a description, list of inputs, and expected output)
  • Placeholder code is flagged / future todos are captured in comments
  • Project documentation has been updated (including the "Unreleased" section of the CHANGELOG)
  • Reviewers requested with the Reviewers tool ➡️

Testing checklist (automated report can be put here)

Target Environment support

  • Linux

@mattw-nws mattw-nws force-pushed the fix-dylib-string-rfind branch from 39876f0 to 22ec5c8 Compare June 23, 2023 18:58
@mattw-nws mattw-nws force-pushed the fix-dylib-string-rfind branch from 22ec5c8 to 5ff23cd Compare June 23, 2023 19:12
@mattw-nws mattw-nws merged commit c261af4 into NOAA-OWP:master Jun 23, 2023
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