set: Skip a wcslen

This commit is contained in:
Fabian Homborg 2022-03-25 16:00:50 +01:00
parent bac2eef496
commit 351cd5bd4b

View file

@ -323,17 +323,17 @@ static maybe_t<split_var_t> split_var_and_indexes(const wchar_t *arg, env_mode_f
const environment_t &vars, const environment_t &vars,
io_streams_t &streams) { io_streams_t &streams) {
split_var_t res{}; split_var_t res{};
const wchar_t *open_bracket = std::wcschr(arg, L'['); wcstring argstr{arg};
size_t varname_len = open_bracket ? open_bracket - arg : wcslen(arg); auto open_bracket = argstr.find(L'[');
res.varname.assign(arg, varname_len); res.varname.assign(arg, open_bracket == wcstring::npos ? argstr.size() : open_bracket);
res.var = vars.get(res.varname, mode); res.var = vars.get(res.varname, mode);
if (!open_bracket) { if (open_bracket == wcstring::npos) {
// Common case of no bracket. // Common case of no bracket.
return res; return res;
} }
long varsize = res.varsize(); long varsize = res.varsize();
const wchar_t *p = open_bracket + 1; const wchar_t *p = arg + open_bracket + 1;
while (*p != L']') { while (*p != L']') {
const wchar_t *end; const wchar_t *end;
long l_ind; long l_ind;