signature: Shut up MSVC, you silly goose
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
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);