Add try-catch around std::stoi#9305
Open
kevinbackhouse wants to merge 2 commits into
Open
Conversation
Collaborator
Author
|
@mergify backport 0.28.x |
Contributor
🟠 Waiting for conditions to matchDetails
|
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds exception handling to time parsing to prevent std::stoi exceptions from aborting parsing, aligning behavior with issue #9299 by returning a warning instead.
Changes:
- Wraps
std::stoicalls inTimeValue::read()with atry/catchto handle invalid syntax/out-of-range inputs gracefully. - Refactors the parsing block by increasing nesting depth (with formatting changes in follow-up commit per description).
Show a summary per file
| File | Description |
|---|---|
src/value.cpp |
Adds try/catch around std::stoi-based parsing and keeps existing range checks to emit warnings instead of throwing. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 3
| return printWarning(); | ||
| time_.tzMinute = time_.tzHour < 0 ? -minute : minute; | ||
| } | ||
| } catch (std::exception&) { |
Comment on lines
+925
to
+928
| auto mi = std::stoi(buf.substr(mpos, 2)); | ||
| if (mi < 0 || mi > 59) | ||
| return printWarning(); | ||
| time_.minute = std::stoi(buf.substr(mpos, 2)); |
| int minute = std::stoi(format.substr(3)); | ||
| if (minute < 0 || minute > 59) | ||
| return printWarning(); | ||
| time_.tzMinute = time_.tzHour < 0 ? -minute : minute; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes: #9299 #9300
Add a try-catch around
std::stoiso that it just prints a warning.The diff looks bigger than it is because the nesting depth changed. I've split it into two commits, with the
clang-formatstep in the second commit.