Skip to content

Guard parseFileAndRemoveComments against a comment before the first newline#146

Merged
maureeungaro merged 1 commit into
gemc:mainfrom
zhaozhiwen:fix/133-comment-strip-npos
Jun 13, 2026
Merged

Guard parseFileAndRemoveComments against a comment before the first newline#146
maureeungaro merged 1 commit into
gemc:mainfrom
zhaozhiwen:fix/133-comment-strip-npos

Conversation

@zhaozhiwen

Copy link
Copy Markdown
Collaborator

parseFileAndRemoveComments computes the newlines around a comment marker and erases between them. rfind('\n') returns npos when the comment is on the first line, and erase(npos, ...) throws std::out_of_range. This treats firstNL==npos as "erase from position 0" and secondNL==npos (comment on the last line, no trailing newline) as "erase to end". Behavior for the common middle-of-file case is unchanged.

Validation: translation unit recompiled cleanly with Geant4 11.4.1 / ROOT 6.38 / Qt 6.9 (ghcr.io/gemc/src:dev-almalinux-10).

Fixes #133

…ewline

rfind('\n') returns npos when a comment marker is on the first line, and
erase(npos, ...) throws std::out_of_range. Treat firstNL==npos as "erase
from position 0" and secondNL==npos (comment on the last line, no
trailing newline) as "erase to end".

Fixes gemc#133

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@maureeungaro maureeungaro merged commit b464ae4 into gemc:main Jun 13, 2026
30 checks passed
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.

[Medium] parseFileAndRemoveComments throws std::out_of_range on a comment before the first newline

2 participants