Commit 41051e3fe1bcb4099714551b61e0b7b06275557c

Vicent Marti 2013-02-20T17:09:51

signature: Shut up MSVC, you silly goose

diff --git a/src/signature.c b/src/signature.c
index ab5882b..a18f104 100644
--- a/src/signature.c
+++ b/src/signature.c
@@ -133,17 +133,14 @@ int git_signature__parse(git_signature *sig, const char **buffer_out,
 	if (header) {
 		const size_t header_len = strlen(header);
 
-		if (buffer_end - buffer < header_len || memcmp(buffer, header, header_len) != 0)
+		if (buffer + header_len >= buffer_end || memcmp(buffer, header, header_len) != 0)
 			return signature_error("expected prefix doesn't match actual");
 
 		buffer += header_len;
 	}
 
-	if (buffer >= buffer_end)
-		return signature_error("signature too short");
-
-	email_start = memrchr(buffer, '<', buffer_end - buffer);
-	email_end = memrchr(buffer, '>', buffer_end - buffer);
+	email_start = git__memrchr(buffer, '<', buffer_end - buffer);
+	email_end = git__memrchr(buffer, '>', buffer_end - buffer);
 
 	if (!email_start || !email_end || email_end <= email_start)
 		return signature_error("malformed e-mail");
diff --git a/src/util.h b/src/util.h
index 351ff42..9dbcb6a 100644
--- a/src/util.h
+++ b/src/util.h
@@ -127,6 +127,21 @@ GIT_INLINE(const char *) git__next_line(const char *s)
 	return s;
 }
 
+GIT_INLINE(const void *) git__memrchr(const void *s, int c, size_t n)
+{
+	const unsigned char *cp;
+
+	if (n != 0) {
+		cp = (unsigned char *)s + n;
+		do {
+			if (*(--cp) == (unsigned char)c)
+				return cp;
+		} while (--n != 0);
+	}
+
+	return NULL;
+}
+
 typedef int (*git__tsort_cmp)(const void *a, const void *b);
 
 extern void git__tsort(void **dst, size_t size, git__tsort_cmp cmp);