Skip to content

Commit

Permalink
git-wrapper: simplify interpolation code
Browse files Browse the repository at this point in the history
After we found the `@@` marker after the key to interpolate, we pretty
much only need the offset *after* the marker. So let's just advance it
instead of adding 2 in many places.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
  • Loading branch information
dscho committed Aug 13, 2016
1 parent 1ad7c02 commit 514335e
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions compat/win32/git-wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,9 @@ static LPWSTR expand_variables(LPWSTR buffer, size_t alloc)
break;

*atat2 = L'\0';
atat2 += 2;
env_len = GetEnvironmentVariable(atat + 2, NULL, 0);
delta = env_len - 1 - (atat2 + 2 - atat);
delta = env_len - 1 - (atat2 - atat);
if (len + delta >= alloc) {
LPWSTR buf2;
alloc = alloc_nr(alloc);
Expand All @@ -264,10 +265,10 @@ static LPWSTR expand_variables(LPWSTR buffer, size_t alloc)
atat2 += buf2 - buf;
buf = buf2;
}
if (delta)
memmove(atat2 + 2 + delta, atat2 + 2,
if (delta > 0)
memmove(atat2 + delta, atat2,
sizeof(WCHAR) * (len + 1
- (atat2 + 2 - buf)));
- (atat2 - buf)));
len += delta;
save = atat[env_len - 1];
GetEnvironmentVariable(atat + 2, atat, env_len);
Expand Down

0 comments on commit 514335e

Please sign in to comment.