All of lore.kernel.org
 help / color / mirror / Atom feed
From: Josh Triplett <josh@freedesktop.org>
To: git@vger.kernel.org
Cc: Daniel Barkalow <barkalow@iabervon.org>
Subject: Re: [PATCH 1/5] Make xstrndup common
Date: Sat, 28 Apr 2007 11:53:13 -0700	[thread overview]
Message-ID: <46339819.8030007@freedesktop.org> (raw)

[-- Attachment #1: Type: text/plain, Size: 653 bytes --]

Daniel Barkalow wrote:
> It was implemented in commit.c; move it with the other x memory functions.
[...]
> +static inline char *xstrndup(const char *str, int len)
> +{
> +	char *ret = xmalloc(len + 1);
> +	memcpy(ret, str, len);
> +	ret[len] = '\0';
> +	return ret;
> +}
> +

I don't know if it matters, but this definition of xstrndup, like the version
in commit.c, doesn't match the definition of strndup.  strndup duplicates a
string, copying up to n characters or the length of the string.  This xstrndup
always copies n characters, reading past the end of the string if it doesn't
have at least n characters.

- Josh Triplett


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 252 bytes --]

             reply	other threads:[~2007-04-28 18:53 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-04-28 18:53 Josh Triplett [this message]
2007-04-28 22:47 ` [PATCH 1/5] Make xstrndup common Junio C Hamano
2007-04-29 18:19 ` Daniel Barkalow
2007-04-29 20:29   ` Josh Triplett
2007-04-29 20:39     ` Junio C Hamano
2007-04-29 20:40     ` Adam Roben
2007-04-30 13:12     ` Johannes Schindelin
2007-04-30 20:50       ` Jeff King
2007-04-30 22:21         ` Johannes Schindelin
  -- strict thread matches above, loose matches on Subject: below --
2007-04-28 17:05 Daniel Barkalow

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=46339819.8030007@freedesktop.org \
    --to=josh@freedesktop.org \
    --cc=barkalow@iabervon.org \
    --cc=git@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.