aboutsummaryrefslogtreecommitdiffhomepage
path: root/parse_util.cpp
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2013-09-21 16:38:57 -0700
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2013-09-21 16:38:57 -0700
commit97ea61a407a1f0987edc09a0ea176413ec3898e4 (patch)
tree1d1e439a2c39c5f41e4976b4f2361384bc0aaeba /parse_util.cpp
parent44bd405ed3c33e6002bdefc83153c94031d3376e (diff)
Fix for parse_util_token_extent doing the wrong thing inside a command
Diffstat (limited to 'parse_util.cpp')
-rw-r--r--parse_util.cpp35
1 files changed, 17 insertions, 18 deletions
diff --git a/parse_util.cpp b/parse_util.cpp
index 5e6f4459..dca23d3e 100644
--- a/parse_util.cpp
+++ b/parse_util.cpp
@@ -411,35 +411,34 @@ void parse_util_token_extent(const wchar_t *buff,
const wchar_t **prev_begin,
const wchar_t **prev_end)
{
- const wchar_t *begin, *end;
- long pos;
-
const wchar_t *a = NULL, *b = NULL, *pa = NULL, *pb = NULL;
CHECK(buff,);
assert(cursor_pos >= 0);
- parse_util_cmdsubst_extent(buff, cursor_pos, &begin, &end);
+ const wchar_t *cmdsubst_begin, *cmdsubst_end;
+ parse_util_cmdsubst_extent(buff, cursor_pos, &cmdsubst_begin, &cmdsubst_end);
- if (!end || !begin)
+ if (!cmdsubst_end || !cmdsubst_begin)
{
return;
}
- pos = cursor_pos - (begin - buff);
+ /* pos is equivalent to cursor_pos within the range of the command substitution {begin, end} */
+ long offset_within_cmdsubst = cursor_pos - (cmdsubst_begin - buff);
- a = buff + pos;
+ a = cmdsubst_begin + offset_within_cmdsubst;
b = a;
- pa = buff + pos;
+ pa = cmdsubst_begin + offset_within_cmdsubst;
pb = pa;
- assert(begin >= buff);
- assert(begin <= (buff+wcslen(buff)));
- assert(end >= begin);
- assert(end <= (buff+wcslen(buff)));
+ assert(cmdsubst_begin >= buff);
+ assert(cmdsubst_begin <= (buff+wcslen(buff)));
+ assert(cmdsubst_end >= cmdsubst_begin);
+ assert(cmdsubst_end <= (buff+wcslen(buff)));
- const wcstring buffcpy = wcstring(begin, end-begin);
+ const wcstring buffcpy = wcstring(cmdsubst_begin, cmdsubst_end-cmdsubst_begin);
tokenizer_t tok(buffcpy.c_str(), TOK_ACCEPT_UNFINISHED | TOK_SQUASH_ERRORS);
for (; tok_has_next(&tok); tok_next(&tok))
@@ -460,9 +459,9 @@ void parse_util_token_extent(const wchar_t *buff,
cursor is between two tokens, so we set it to a zero element
string and break
*/
- if (tok_begin > pos)
+ if (tok_begin > offset_within_cmdsubst)
{
- a = b = (wchar_t *)buff + pos;
+ a = b = cmdsubst_begin + offset_within_cmdsubst;
break;
}
@@ -470,9 +469,9 @@ void parse_util_token_extent(const wchar_t *buff,
If cursor is inside the token, this is the token we are
looking for. If so, set a and b and break
*/
- if ((tok_last_type(&tok) == TOK_STRING) && (tok_end >= pos))
+ if ((tok_last_type(&tok) == TOK_STRING) && (tok_end >= offset_within_cmdsubst))
{
- a = begin + tok_get_pos(&tok);
+ a = cmdsubst_begin + tok_get_pos(&tok);
b = a + wcslen(tok_last(&tok));
break;
}
@@ -482,7 +481,7 @@ void parse_util_token_extent(const wchar_t *buff,
*/
if (tok_last_type(&tok) == TOK_STRING)
{
- pa = begin + tok_get_pos(&tok);
+ pa = cmdsubst_begin + tok_get_pos(&tok);
pb = pa + wcslen(tok_last(&tok));
}
}