Skip to content

Commit

Permalink
FIX: Potential uninitialised value returned if empty string passed to…
Browse files Browse the repository at this point in the history
… from_string<T>() (#1087)
  • Loading branch information
braindigitalis authored Feb 19, 2024
1 parent fdfe48b commit 23a9932
Show file tree
Hide file tree
Showing 4 changed files with 283 additions and 21 deletions.
5 changes: 4 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@
"sku",
"skus",
"Codecademy",
"tparam"
"tparam",
"khanda",
"oclock",
"moai"
],
"flagWords": [
"hte"
Expand Down
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
"semaphore": "cpp",
"stop_token": "cpp",
"charconv": "cpp",
"any": "cpp"
"any": "cpp",
"ranges": "cpp",
"span": "cpp"
}
}
3 changes: 3 additions & 0 deletions include/dpp/stringops.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ template <typename T> T from_string(const std::string &s, std::ios_base & (*f)(s
*/
template <typename T> T from_string(const std::string &s)
{
if (s.empty()) {
return static_cast<T>(0);
}
T t;
std::istringstream iss(s);
iss >> t;
Expand Down
Loading

0 comments on commit 23a9932

Please sign in to comment.