[RFC 1/7] check_refname_component(): iterate via index rather than via pointer

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

 



From: Michael Haggerty <mhagger@xxxxxxxxxxxx>

This will make later changes easier.

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

diff --git a/refs.c b/refs.c
index 09322fe..927d36c 100644
--- a/refs.c
+++ b/refs.c
@@ -35,12 +35,12 @@ static inline int bad_ref_char(int ch)
  */
 static int check_refname_component(const char *refname, int flags)
 {
-	const char *cp;
+	int i, len = strlen(refname);
 	char last = '\0';
 
-	for (cp = refname; ; cp++) {
-		char ch = *cp;
-		if (ch == '\0' || ch == '/')
+	for (i = 0; i < len; i++) {
+		char ch = refname[i];
+		if (ch == '/')
 			break;
 		if (bad_ref_char(ch))
 			return -1; /* Illegal character in refname. */
@@ -50,7 +50,7 @@ static int check_refname_component(const char *refname, int flags)
 			return -1; /* Refname contains "@{". */
 		last = ch;
 	}
-	if (cp == refname)
+	if (i == 0)
 		return 0; /* Component has zero length. */
 	if (refname[0] == '.') {
 		if (!(flags & REFNAME_DOT_COMPONENT))
@@ -59,12 +59,12 @@ static int check_refname_component(const char *refname, int flags)
 		 * Even if leading dots are allowed, don't allow "."
 		 * as a component (".." is prevented by a rule above).
 		 */
-		if (refname[1] == '\0')
+		if (len == 1)
 			return -1; /* Component equals ".". */
 	}
-	if (cp - refname >= 5 && !memcmp(cp - 5, ".lock", 5))
+	if (i >= 5 && !memcmp(&refname[i - 5], ".lock", 5))
 		return -1; /* Refname ends with ".lock". */
-	return cp - refname;
+	return i;
 }
 
 int check_refname_format(const char *refname, int flags)
-- 
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]