Andrew's git
/
gitweb.git
/ diff
summary
|
log
|
commit
| diff |
tree
commit
grep
author
committer
pickaxe
?
re
refs: convert parameter of search_ref_dir() to length-limited string
author
René Scharfe
<rene.scharfe@lsrfire.ath.cx>
Tue, 22 May 2012 18:50:39 +0000
(20:50 +0200)
committer
Junio C Hamano
<gitster@pobox.com>
Tue, 22 May 2012 20:32:21 +0000
(13:32 -0700)
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
refs.c
patch
|
blob
|
history
raw
|
patch
|
inline
| side by side (parent:
aa3bb87
)
diff --git
a/refs.c
b/refs.c
index d6bdb47ad61dc5e7eb1c786dd4115e17bdb2aab7..c0283338695507c0aac81fda4c7bf8ad7712d049 100644
(file)
--- 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.
*/
* (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;
{
struct ref_entry *e, **r;
- int len;
if (refname == NULL || !dir->nr)
return NULL;
sort_ref_dir(dir);
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);
memcpy(e->name, refname, len);
+ e->name[len] = '\0';
r = bsearch(&e, dir->entries, dir->nr, sizeof(*dir->entries), ref_entry_cmp);
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)
{
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;
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;
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;
}
return (entry && !(entry->flag & REF_DIR)) ? entry : NULL;
}