Skip to content

Commit

Permalink
Modify wrong memory reference
Browse files Browse the repository at this point in the history
 - If input is a string of only spaces,
   index becomes -1 during removes trailing spaces operation,
   referencing the wrong memory.
 - If the referenced memory value is a space,
   out_of_range occurs
   because -1 is entered in the erase function pos parameter.
 - Modify to return immediately if the input value is empty
   after the removes leading spaces operation.
  • Loading branch information
kimokd committed Mar 31, 2021
1 parent 119a70b commit 5dd5158
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions mimetic/strutils.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ string canonical(const string& s, bool no_ws)
idx++;
if(idx)
input.erase(0, idx);

if(input.empty())
return input;

// removes trailing spaces
idx = input.length() - 1;
while(input[idx] == ' ')
Expand Down

0 comments on commit 5dd5158

Please sign in to comment.