summaryrefslogtreecommitdiff
path: root/compat
diff options
context:
space:
mode:
authorDerrick Stolee <derrickstolee@github.com>2022-07-19 18:45:54 (GMT)
committerJunio C Hamano <gitster@pobox.com>2022-07-19 19:51:34 (GMT)
commitb4f52f09ae712e1a813375712b6e58be49255cd0 (patch)
treec3f277b4d616e44dd9c4a3d4543fa86faa1998e9 /compat
parentbbea4dcf42b28eb7ce64a6306cdde875ae5d09ca (diff)
downloadgit-b4f52f09ae712e1a813375712b6e58be49255cd0.zip
git-b4f52f09ae712e1a813375712b6e58be49255cd0.tar.gz
git-b4f52f09ae712e1a813375712b6e58be49255cd0.tar.bz2
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>
Diffstat (limited to 'compat')
-rw-r--r--compat/win32/syslog.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/compat/win32/syslog.c b/compat/win32/syslog.c
index 1f8d893..0af18d8 100644
--- a/compat/win32/syslog.c
+++ b/compat/win32/syslog.c
@@ -44,6 +44,7 @@ void syslog(int priority, const char *fmt, ...)
while ((pos = strstr(str, "%1")) != NULL) {
size_t offset = pos - str;
+ char *new_pos;
char *oldstr = str;
str = realloc(str, st_add(++str_len, 1));
if (!str) {
@@ -51,9 +52,9 @@ void syslog(int priority, const char *fmt, ...)
warning_errno("realloc failed");
return;
}
- pos = str + offset;
- memmove(pos + 2, pos + 1, strlen(pos));
- pos[1] = ' ';
+ new_pos = str + offset;
+ memmove(new_pos + 2, new_pos + 1, strlen(new_pos));
+ new_pos[1] = ' ';
}
switch (priority) {