Skip to content

Commit b01376a

Browse files
committed
git-wrapper: make the interpolation code easier to understand
When moving bytes (because the name and the value of the environment variable to interpolate differ in length), we introduce a variable to unclutter the code and make it more obvious what is happening. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 6f24332 commit b01376a

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

compat/win32/git-wrapper.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ static void extract_first_arg(LPWSTR command_line, LPWSTR exepath, LPWSTR buf)
224224
static LPWSTR expand_variables(LPWSTR buffer, size_t alloc)
225225
{
226226
LPWSTR buf = buffer;
227-
size_t len = wcslen(buf);
227+
size_t len = wcslen(buf), move_len;
228228

229229
for (;;) {
230230
LPWSTR atat = wcsstr(buf, L"@@"), atat2;
@@ -265,10 +265,9 @@ static LPWSTR expand_variables(LPWSTR buffer, size_t alloc)
265265
atat2 += buf2 - buf;
266266
buf = buf2;
267267
}
268+
move_len = sizeof(WCHAR) * (len + 1 - (atat2 - buf));
268269
if (delta > 0)
269-
memmove(atat2 + delta, atat2,
270-
sizeof(WCHAR) * (len + 1
271-
- (atat2 - buf)));
270+
memmove(atat2 + delta, atat2, move_len);
272271
len += delta;
273272
save = atat[env_len - 1];
274273
GetEnvironmentVariable(atat + 2, atat, env_len);

0 commit comments

Comments
 (0)