Juergen Ruehle [off-list ref] writes:
This might have been fixed already (my tree is a couple of days old),
but the strcat fails for me, because the alloced memory is not
cleared.
Johannes Schindelin writes:
> +static const char *add_slash(const char *path)
> +{
> + int len = strlen(path);
> + if (path[len - 1] != '/') {
> + char *with_slash = xmalloc(len + 2);
> + memcpy(with_slash, path, len);
> + strcat(with_slash + len, "/");
> + return with_slash;
> + }
> + return path;
> +}
perhaps morph the strcat into a memcopy or append the slash and the
NUL manually?
Thanks, well spotted. A textually minimum change would be to
do:
- memcpy(with_slash, path, len);
+ memcpy(with_slash, path, len + 1);
but that would touch the end of the string twice, so manually
terminating the string with '/' NUL would be appropriate.
I will apply a patch I've been privately using from time to time
to catch something like this to "master".
-- >8 --
[PATCH] debugging: XMALLOC_POISON
Compile with -DXMALLOC_POISON=1 to catch errors from using uninitialized
memory returned by xmalloc.
Signed-off-by: Junio C Hamano <redacted>
---
git-compat-util.h | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/git-compat-util.h b/git-compat-util.h
index 93f5580..3bcf5b1 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -91,6 +91,9 @@ static inline void *xmalloc(size_t size)
ret = malloc(1);
if (!ret)
die("Out of memory, malloc failed");
+#ifdef XMALLOC_POISON
+ memset(ret, 0xA5, size);
+#endif
return ret;
}
--
1.4.2.rc3.g45c5