Code

resolve_ref(): use prefixcmp()
authorMichael Haggerty <mhagger@alum.mit.edu>
Thu, 15 Sep 2011 21:10:32 +0000 (23:10 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 5 Oct 2011 20:45:30 +0000 (13:45 -0700)
Terminate the link content string one step earlier, allowing
prefixcmp() to be used instead of the less clear memcmp().

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
refs.c

diff --git a/refs.c b/refs.c
index c51fd45f99ef3a6d5fdb56b6bd5ba9a554f2e8f8..da9737f9920b7592b271c1fe7b1864ecd4d80ce4 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -520,8 +520,8 @@ const char *resolve_ref(const char *ref, unsigned char *sha1, int reading, int *
                        len = readlink(path, buffer, sizeof(buffer)-1);
                        if (len < 0)
                                return NULL;
-                       if (len >= 5 && !memcmp("refs/", buffer, 5)) {
-                               buffer[len] = 0;
+                       buffer[len] = 0;
+                       if (!prefixcmp(buffer, "refs/")) {
                                strcpy(ref_buffer, buffer);
                                ref = ref_buffer;
                                if (flag)