Skip to content

Commit 59cb919

Browse files
committed
fix: handle string::npos case in a cleaner way
1 parent 98d5c1f commit 59cb919

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

packages/machine-id/binding.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,12 @@ namespace
5656
{
5757
return str;
5858
}
59-
6059
std::string result = str;
61-
result.erase(result.find_last_not_of(" \n\r\t") + 1);
60+
size_t from_right = result.find_last_not_of(" \n\r\t");
61+
if (from_right != std::string::npos)
62+
{
63+
result.erase(from_right + 1);
64+
}
6265
result.erase(0, result.find_first_not_of(" \n\r\t"));
6366
return result;
6467
}

0 commit comments

Comments
 (0)