git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "David Rydh" <dary@math.berkeley.edu>
Cc: "git\@vger.kernel.org" <git@vger.kernel.org>,
	"Johannes Sixt" <j6t@kdbg.org>
Subject: Re: [PATCH] git-mv: Fix error with multiple sources.
Date: Thu, 21 Jan 2010 22:24:19 -0800	[thread overview]
Message-ID: <7vd412ac8c.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <718290.769818367-sendEmail@darysmbp> (David Rydh's message of "Thu\, 21 Jan 2010 12\:39\:41 -0800")

"David Rydh" <dary@math.berkeley.edu> writes:

> diff --git a/builtin-mv.c b/builtin-mv.c
> index 8247186..1c1f8be 100644
> --- a/builtin-mv.c
> +++ b/builtin-mv.c
> @@ -27,7 +27,7 @@ static const char **copy_pathspec(const char *prefix, const char **pathspec,
>  		if (length > 0 && is_dir_sep(result[i][length - 1]))
>  			result[i] = xmemdupz(result[i], length - 1);
>  		if (base_name)
> -			result[i] = basename((char *)result[i]);
> +			result[i] = xstrdup(basename((char *)result[i]));
>  	}
>  	return get_pathspec(prefix, result);
>  }

Given that basename(3) is allowed to modify its parameter, I think the
above code is still not portable.  casting constness away and feeding
result[i], especially when we didn't obtain our own copy by calling
xmemdupz(), is especially problematic.

Perhaps something ugly like this?

	for (i = 0; i < count; i++) {
		int length = strlen(result[i]);
		int to_copy = length;
                while (to_copy > 0 && is_dir_sep(result[i][to_copy - 1]))
			to_copy--;
		if (to_copy != length || basename) {
                	char *it = xmemdupz(result[i], to_copy);
                        result[i] = base_name ? strdup(basename(it)) : it;
		}
	}

  parent reply	other threads:[~2010-01-22  6:24 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-21 20:39 [PATCH] git-mv: Fix error with multiple sources David Rydh
2010-01-22  5:57 ` Junio C Hamano
2010-01-22 16:41   ` David Rydh
2010-01-22  6:17 ` Junio C Hamano
2010-01-22 16:49   ` David Rydh
2010-01-22  6:24 ` Junio C Hamano [this message]
     [not found]   ` <7vr5pi8x6z.fsf@alter.siamese.dyndns.org>
2010-01-22 17:30     ` David Rydh
2010-01-22 18:34     ` Johannes Sixt
2010-01-22  7:03 ` Matthieu Moy
2010-01-22  7:29 ` Johannes Sixt

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=7vd412ac8c.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=dary@math.berkeley.edu \
    --cc=git@vger.kernel.org \
    --cc=j6t@kdbg.org \
    /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;
as well as URLs for NNTP newsgroup(s).