Skip to content

Commit d11f41d

Browse files
committed
git-wrapper: fix interpolation with short values
To be precise: when the value of the environment variable is shorter than its name, we have to move the remaining bytes *after* expanding the environment variable: we would look for the wrong name otherwise. When the value is longer than the name, we still need to move the bytes out of the way first, to avoid overwriting them with the interpolated text. This fixes #509 Signed-off-by: Johannes Schindelin <[email protected]>
1 parent b01376a commit d11f41d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

compat/win32/git-wrapper.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,10 @@ static LPWSTR expand_variables(LPWSTR buffer, size_t alloc)
269269
if (delta > 0)
270270
memmove(atat2 + delta, atat2, move_len);
271271
len += delta;
272-
save = atat[env_len - 1];
272+
save = atat[env_len - 1 + (delta < 0 ? -delta : 0)];
273273
GetEnvironmentVariable(atat + 2, atat, env_len);
274+
if (delta < 0)
275+
memmove(atat2 + delta, atat2, move_len);
274276
atat[env_len - 1] = save;
275277
}
276278

0 commit comments

Comments
 (0)