Skip to content

Commit

Permalink
refactor: std::string -> std::string_view
Browse files Browse the repository at this point in the history
Safer after recent fix to make TxidFromString() respect string_view length. The internal call to uint256S() when parsing the txid would still have stopped at the '-'-symbol in this case though.
  • Loading branch information
hodlinator committed Jul 12, 2024
1 parent a4ead4e commit be23937
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/rest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -789,8 +789,9 @@ static bool rest_getutxos(const std::any& context, HTTPRequest* req, const std::
for (size_t i = (fCheckMemPool) ? 1 : 0; i < uriParts.size(); i++)
{
int32_t nOutput;
std::string strTxid = uriParts[i].substr(0, uriParts[i].find('-'));
std::string strOutput = uriParts[i].substr(uriParts[i].find('-')+1);
const std::string_view part{uriParts[i]};
const std::string_view strTxid{part.substr(0, part.find('-'))};
const std::string_view strOutput{part.substr(strTxid.size()+1)};

if (!ParseInt32(strOutput, &nOutput) || !IsHex(strTxid))
return RESTERR(req, HTTP_BAD_REQUEST, "Parse error");
Expand Down

0 comments on commit be23937

Please sign in to comment.