From 837f72dabd7174b85ff7665f1839ee4b0a5699fc Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sun, 1 Nov 2015 18:26:16 +0100 Subject: [PATCH] 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 --- compat/win32/git-wrapper.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/compat/win32/git-wrapper.c b/compat/win32/git-wrapper.c index 65a0001c26ab91..3b2791b36c2ca2 100644 --- a/compat/win32/git-wrapper.c +++ b/compat/win32/git-wrapper.c @@ -224,7 +224,7 @@ static void extract_first_arg(LPWSTR command_line, LPWSTR exepath, LPWSTR buf) static LPWSTR expand_variables(LPWSTR buffer, size_t alloc) { LPWSTR buf = buffer; - size_t len = wcslen(buf); + size_t len = wcslen(buf), move_len; for (;;) { LPWSTR atat = wcsstr(buf, L"@@"), atat2; @@ -265,10 +265,9 @@ static LPWSTR expand_variables(LPWSTR buffer, size_t alloc) atat2 += buf2 - buf; buf = buf2; } + move_len = sizeof(WCHAR) * (len + 1 - (atat2 - buf)); if (delta > 0) - memmove(atat2 + delta, atat2, - sizeof(WCHAR) * (len + 1 - - (atat2 - buf))); + memmove(atat2 + delta, atat2, move_len); len += delta; save = atat[env_len - 1]; GetEnvironmentVariable(atat + 2, atat, env_len);