[RFC 3/7] parse_refname_component(): accept a length parameter

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Michael Haggerty <mhagger@xxxxxxxxxxxx>


Signed-off-by: Michael Haggerty <mhagger@xxxxxxxxxxxx>
---
 refs.c |   16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/refs.c b/refs.c
index c293fd2..39008f2 100644
--- a/refs.c
+++ b/refs.c
@@ -29,16 +29,16 @@ static inline int bad_ref_char(int ch)
 }
 
 /*
- * Try to read one refname component from the front of refname.  Return
- * the length of the component found, or -1 if the component is not
- * legal.
+ * Try to read one refname component from the first refnamelen
+ * characters of refname.  Return the length of the component found,
+ * or -1 if the component is not legal.
  */
-static int check_refname_component(const char *refname, int flags)
+static int check_refname_component(const char *refname, int refnamelen, int flags)
 {
-	int i, len = strlen(refname);
+	int i;
 	char last = '\0';
 
-	for (i = 0; i < len; i++) {
+	for (i = 0; i < refnamelen; i++) {
 		char ch = refname[i];
 		if (ch == '/')
 			break;
@@ -69,11 +69,12 @@ static int check_refname_component(const char *refname, int flags)
 
 int check_refname_format(const char *refname, int flags)
 {
+	int refnamelen = strlen(refname);
 	int component_len, component_count = 0;
 
 	while (1) {
 		/* We are at the start of a path component. */
-		component_len = check_refname_component(refname, flags);
+		component_len = check_refname_component(refname, refnamelen, flags);
 		if (component_len <= 0) {
 			if ((flags & REFNAME_REFSPEC_PATTERN) &&
 					refname[0] == '*' &&
@@ -90,6 +91,7 @@ int check_refname_format(const char *refname, int flags)
 			break;
 		/* Skip to next component. */
 		refname += component_len + 1;
+		refnamelen -= component_len + 1;
 	}
 
 	if (refname[component_len - 1] == '.')
-- 
1.7.10

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]