From: "René Scharfe" <rene.scharfe@lsrfire.ath.cx>
To: mhagger@alum.mit.edu
Cc: Jeff King <peff@peff.net>, Junio C Hamano <gitster@pobox.com>,
git@vger.kernel.org
Subject: [PATCH 1/3] refs: convert parameter of search_ref_dir() to length-limited string
Date: Tue, 22 May 2012 20:50:39 +0200 [thread overview]
Message-ID: <4FBBDFFF.8050207@lsrfire.ath.cx> (raw)
In-Reply-To: <1337692566-3718-1-git-send-email-mhagger@alum.mit.edu>
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
---
refs.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/refs.c b/refs.c
index d6bdb47..c028333 100644
--- a/refs.c
+++ b/refs.c
@@ -319,19 +319,19 @@ static void sort_ref_dir(struct ref_dir *dir);
* (non-recursively), sorting dir if necessary. Return NULL if no
* such entry is found. dir must already be complete.
*/
-static struct ref_entry *search_ref_dir(struct ref_dir *dir, const char *refname)
+static struct ref_entry *search_ref_dir(struct ref_dir *dir,
+ const char *refname, size_t len)
{
struct ref_entry *e, **r;
- int len;
if (refname == NULL || !dir->nr)
return NULL;
sort_ref_dir(dir);
- len = strlen(refname) + 1;
- e = xmalloc(sizeof(struct ref_entry) + len);
+ e = xmalloc(sizeof(struct ref_entry) + len + 1);
memcpy(e->name, refname, len);
+ e->name[len] = '\0';
r = bsearch(&e, dir->entries, dir->nr, sizeof(*dir->entries), ref_entry_cmp);
@@ -353,7 +353,8 @@ static struct ref_entry *search_ref_dir(struct ref_dir *dir, const char *refname
static struct ref_dir *search_for_subdir(struct ref_dir *dir,
const char *subdirname, int mkdir)
{
- struct ref_entry *entry = search_ref_dir(dir, subdirname);
+ size_t len = strlen(subdirname);
+ struct ref_entry *entry = search_ref_dir(dir, subdirname, len);
if (!entry) {
if (!mkdir)
return NULL;
@@ -412,7 +413,7 @@ static struct ref_entry *find_ref(struct ref_dir *dir, const char *refname)
dir = find_containing_dir(dir, refname, 0);
if (!dir)
return NULL;
- entry = search_ref_dir(dir, refname);
+ entry = search_ref_dir(dir, refname, strlen(refname));
return (entry && !(entry->flag & REF_DIR)) ? entry : NULL;
}
--
1.7.10.2
next prev parent reply other threads:[~2012-05-22 18:51 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-22 13:16 [PATCH] find_containing_dir(): allocate strbuf less extravagantly mhagger
2012-05-22 17:34 ` Jeff King
2012-05-22 18:50 ` René Scharfe [this message]
2012-05-22 18:50 ` [PATCH 2/3] refs: convert parameter of create_dir_entry() to length-limited string René Scharfe
2012-05-22 18:50 ` [PATCH 3/3] refs: use strings directly in find_containing_dir() René Scharfe
2012-05-22 21:27 ` Junio C Hamano
2012-05-22 22:11 ` René Scharfe
2012-05-22 22:18 ` Junio C Hamano
2012-05-23 16:20 ` René Scharfe
2012-05-23 16:56 ` Junio C Hamano
2012-05-23 17:15 ` René Scharfe
2012-05-24 4:34 ` Michael Haggerty
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=4FBBDFFF.8050207@lsrfire.ath.cx \
--to=rene.scharfe@lsrfire.ath.cx \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=mhagger@alum.mit.edu \
--cc=peff@peff.net \
/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.