Skip to content

Add try-catch around std::stoi#9305

Open
kevinbackhouse wants to merge 2 commits into
Exiv2:mainfrom
kevinbackhouse:fix-issue-9299
Open

Add try-catch around std::stoi#9305
kevinbackhouse wants to merge 2 commits into
Exiv2:mainfrom
kevinbackhouse:fix-issue-9299

Conversation

@kevinbackhouse
Copy link
Copy Markdown
Collaborator

@kevinbackhouse kevinbackhouse commented May 23, 2026

Fixes: #9299 #9300

Add a try-catch around std::stoi so 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-format step in the second commit.

Copilot AI review requested due to automatic review settings May 23, 2026 09:58
@kevinbackhouse
Copy link
Copy Markdown
Collaborator Author

@mergify backport 0.28.x

@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented May 23, 2026

backport 0.28.x

🟠 Waiting for conditions to match

Details
  • merged [📌 backport requirement]

@kevinbackhouse kevinbackhouse changed the title Fix issue 9299 Add try-catch around std::stoi May 23, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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::stoi calls in TimeValue::read() with a try/catch to 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

Comment thread src/value.cpp
return printWarning();
time_.tzMinute = time_.tzHour < 0 ? -minute : minute;
}
} catch (std::exception&) {
Comment thread src/value.cpp
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));
Comment thread src/value.cpp
int minute = std::stoi(format.substr(3));
if (minute < 0 || minute > 59)
return printWarning();
time_.tzMinute = time_.tzHour < 0 ? -minute : minute;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants