From: Junio C Hamano <junkio@cox.net>
To: Juergen Ruehle <j.ruehle@bmiag.de>
Cc: Johannes Schindelin <Johannes.Schindelin@gmx.de>,
Jon Smirl <jonsmirl@gmail.com>,
git@vger.kernel.org,
Josef Weidendorfer <Josef.Weidendorfer@gmx.de>
Subject: Re: [PATCH 2/2] builtin git-mv: support moving directories
Date: Tue, 08 Aug 2006 12:52:27 -0700 [thread overview]
Message-ID: <7virl3vwck.fsf@assigned-by-dhcp.cox.net> (raw)
In-Reply-To: <17624.55600.423000.61479@lapjr.intranet.kiel.bmiag.de> (Juergen Ruehle's message of "Tue, 8 Aug 2006 20:34:24 +0200")
Juergen Ruehle <j.ruehle@bmiag.de> 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 <junkio@cox.net>
---
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
next prev parent reply other threads:[~2006-08-08 19:52 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-07-26 17:47 [PATCH 2/2] builtin git-mv: support moving directories Johannes Schindelin
2006-07-26 19:58 ` Junio C Hamano
2006-08-08 18:34 ` Juergen Ruehle
2006-08-08 19:52 ` Junio C Hamano [this message]
2006-08-08 22:36 ` [PATCH] mv: strcat -> strcpy to account for uninitialized memory Johannes Schindelin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7virl3vwck.fsf@assigned-by-dhcp.cox.net \
--to=junkio@cox.net \
--cc=Johannes.Schindelin@gmx.de \
--cc=Josef.Weidendorfer@gmx.de \
--cc=git@vger.kernel.org \
--cc=j.ruehle@bmiag.de \
--cc=jonsmirl@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox