compat/win32: correct for incorrect compiler warning

The 'win build' job of our CI build is failing with the following error: compat/win32/syslog.c: In function 'syslog': compat/win32/syslog.c:53:17: error: pointer 'pos' may be used after \ 'realloc' [-Werror=use-after-free] 53 | memmove(pos + 2, pos + 1, strlen(pos)); CC compat/poll/poll.o | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ compat/win32/syslog.c:47:23: note: call to 'realloc' here 47 | str = realloc(str, st_add(++str_len, 1)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ However, between this realloc() and the use we have a line that resets the value of 'pos'. Thus, this error is incorrect. It is likely due to a new version of the compiler on the CI machines. Instead of waiting for a new compiler, create a new variable to avoid this error. Signed-off-by: Derrick Stolee <derrickstolee@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Jul 19, 2022 at 18:45 UTC b4f52f09ae712e1a813375712b6e58be49255cd0
1 file changed +4 -3
compat/win32/syslog.c
+4 -3
@@ -44,6 +44,7 @@ void syslog(int priority, const char *fmt, ...)
44
45 while ((pos = strstr(str, "%1")) != NULL) {
46 size_t offset = pos - str;
47 + char *new_pos;
48 char *oldstr = str;
49 str = realloc(str, st_add(++str_len, 1));
50 if (!str) {
@@ -51,9 +52,9 @@ void syslog(int priority, const char *fmt, ...)
52 warning_errno("realloc failed");
53 return;
54 }
54 - pos = str + offset;
55 - memmove(pos + 2, pos + 1, strlen(pos));
56 - pos[1] = ' ';
55 + new_pos = str + offset;
56 + memmove(new_pos + 2, new_pos + 1, strlen(new_pos));
57 + new_pos[1] = ' ';
58 }
59
60 switch (priority) {