summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 1f8115b)
raw | patch | inline | side by side (parent: 1f8115b)
author | Krzysztof Kowalczyk <kkowalczyk@gmail.com> | |
Sat, 10 May 2008 23:26:58 +0000 (16:26 -0700) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Sun, 11 May 2008 16:04:37 +0000 (09:04 -0700) |
Also fix an underallocation in walker.c::interpret_target().
Signed-off-by: Krzysztof Kowalczyk <kkowalczyk@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Krzysztof Kowalczyk <kkowalczyk@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin-fetch.c | patch | blob | history | |
http-push.c | patch | blob | history | |
remote.c | patch | blob | history | |
remote.h | patch | blob | history | |
transport.c | patch | blob | history | |
walker.c | patch | blob | history |
diff --git a/builtin-fetch.c b/builtin-fetch.c
index e56617e32e5f878e1ae9f0d94ceced28ba18a94e..f6584ecea165704208059b632bb1a1ac2b6a6d1f 100644 (file)
--- a/builtin-fetch.c
+++ b/builtin-fetch.c
will_fetch(head, ref->old_sha1))) {
path_list_insert(ref_name, &new_refs);
- rm = alloc_ref(strlen(ref_name) + 1);
- strcpy(rm->name, ref_name);
- rm->peer_ref = alloc_ref(strlen(ref_name) + 1);
- strcpy(rm->peer_ref->name, ref_name);
+ rm = alloc_ref_from_str(ref_name);
+ rm->peer_ref = alloc_ref_from_str(ref_name);
hashcpy(rm->old_sha1, ref_sha1);
**tail = rm;
diff --git a/http-push.c b/http-push.c
index 939a76460232f9097b20e43d71b35efbdad97b52..42727c8a45c7b50e8e6b2b04a0799c9ba85a0114 100644 (file)
--- a/http-push.c
+++ b/http-push.c
struct ref *ref;
struct object *obj;
- ref = alloc_ref(strlen(refname) + 1);
- strcpy(ref->name, refname);
+ ref = alloc_ref_from_str(refname);
if (http_fetch_ref(remote->url, ref) != 0) {
fprintf(stderr,
char *ref_info;
struct ref *ref;
- ref = alloc_ref(strlen(ls->dentry_name) + 1);
- strcpy(ref->name, ls->dentry_name);
+ ref = alloc_ref_from_str(ls->dentry_name);
if (http_fetch_ref(remote->url, ref) != 0) {
fprintf(stderr,
diff --git a/remote.c b/remote.c
index 6b480cbb9808d9e2b77f2a88f0324701e02a8a75..91cbb72ddeba1c60dab7aad2105e1c004ea6e198 100644 (file)
--- a/remote.c
+++ b/remote.c
return ret;
}
+struct ref *alloc_ref_from_str(const char* str)
+{
+ struct ref *ret = alloc_ref(strlen(str) + 1);
+ strcpy(ret->name, str);
+ return ret;
+}
+
static struct ref *copy_ref(const struct ref *ref)
{
struct ref *ret = xmalloc(sizeof(struct ref) + strlen(ref->name) + 1);
{
unsigned char sha1[20];
struct ref *ref;
- int len;
if (!*name) {
ref = alloc_ref(20);
}
if (get_sha1(name, sha1))
return NULL;
- len = strlen(name) + 1;
- ref = alloc_ref(len);
- memcpy(ref->name, name, len);
+ ref = alloc_ref_from_str(name);
hashcpy(ref->new_sha1, sha1);
return ref;
}
static struct ref *make_linked_ref(const char *name, struct ref ***tail)
{
- struct ref *ret;
- size_t len;
-
- len = strlen(name) + 1;
- ret = alloc_ref(len);
- memcpy(ret->name, name, len);
+ struct ref *ret = alloc_ref_from_str(name);
tail_link_ref(ret, tail);
return ret;
}
return NULL;
if (!prefixcmp(name, "refs/")) {
- ret = alloc_ref(strlen(name) + 1);
- strcpy(ret->name, name);
- return ret;
+ return alloc_ref_from_str(name);
}
if (!prefixcmp(name, "heads/") ||
diff --git a/remote.h b/remote.h
index 75d006b6deb2ded726df2c1749aa63dec69e34d2..2ee83a33b3bb7ddaa5bb33493dacfbeca4ae5dbe 100644 (file)
--- a/remote.h
+++ b/remote.h
struct ref *alloc_ref(unsigned namelen);
+struct ref *alloc_ref_from_str(const char* str);
+
struct ref *copy_ref_list(const struct ref *ref);
int check_ref_type(const struct ref *ref, int flags);
diff --git a/transport.c b/transport.c
index b012a283386de601a7f5df15b11b659c5297f21d..1bc16f2b65f46650c53227758df8431cf5a77598 100644 (file)
--- a/transport.c
+++ b/transport.c
strbuf_release(&buffer);
- ref = alloc_ref(strlen("HEAD") + 1);
- strcpy(ref->name, "HEAD");
+ ref = alloc_ref_from_str("HEAD");
if (!walker->fetch_ref(walker, ref) &&
!resolve_remote_symref(ref, refs)) {
ref->next = refs;
die ("Could not read bundle '%s'.", transport->url);
for (i = 0; i < data->header.references.nr; i++) {
struct ref_list_entry *e = data->header.references.list + i;
- struct ref *ref = alloc_ref(strlen(e->name) + 1);
+ struct ref *ref = alloc_ref_from_str(e->name);
hashcpy(ref->old_sha1, e->sha1);
- strcpy(ref->name, e->name);
ref->next = result;
result = ref;
}
diff --git a/walker.c b/walker.c
index fa96a7c7d293ee43a86317c8407d4e960311d59e..31de6c16bd021003bdd4fc1475bfe500f28773f4 100644 (file)
--- a/walker.c
+++ b/walker.c
@@ -190,8 +190,7 @@ static int interpret_target(struct walker *walker, char *target, unsigned char *
if (!get_sha1_hex(target, sha1))
return 0;
if (!check_ref_format(target)) {
- struct ref *ref = alloc_ref(strlen(target));
- strcpy(ref->name, target);
+ struct ref *ref = alloc_ref_from_str(target);
if (!walker->fetch_ref(walker, ref)) {
hashcpy(sha1, ref->old_sha1);
free(ref);