svn commit: r184884 - projects/csup_cvsmode/contrib/csup

Ulf Lilleengen lulf at FreeBSD.org
Wed Nov 12 06:29:24 PST 2008


Author: lulf
Date: Wed Nov 12 14:29:24 2008
New Revision: 184884
URL: http://svn.freebsd.org/changeset/base/184884

Log:
  - Fix idiotic rcsnum_cmp and compare the revision numbers without allocating any
    memory.

Modified:
  projects/csup_cvsmode/contrib/csup/misc.c

Modified: projects/csup_cvsmode/contrib/csup/misc.c
==============================================================================
--- projects/csup_cvsmode/contrib/csup/misc.c	Wed Nov 12 14:16:39 2008	(r184883)
+++ projects/csup_cvsmode/contrib/csup/misc.c	Wed Nov 12 14:29:24 2008	(r184884)
@@ -578,44 +578,24 @@ bt_free(struct backoff_timer *bt)
 int
 rcsnum_cmp(char *revision1, char *revision2)
 {
-	char *rev1, *rev2, *rev1orig, *rev2orig;
-	char *tmp1, *tmp2;
-	long num1, num2;
-	int retval;
-
-	rev1orig = xstrdup(revision1);
-	rev2orig = xstrdup(revision2);
-	retval = 0;
-
-	rev1 = rev1orig;
-	rev2 = rev2orig;
-	tmp1 = strsep(&rev1, ".");
-	tmp2 = strsep(&rev2, ".");
-	while (tmp1 != NULL && tmp2 != NULL) {
-		num1 = strtol(tmp1, NULL, 10);
-		num2 = strtol(tmp2, NULL, 10);
-		if (num1 > num2) {
-			retval = 1;
-			goto done;
-		} else if (num1 < num2) {
-			retval = -1;
-			goto done;
-		}
-		tmp1 = strsep(&rev1, ".");
-		tmp2 = strsep(&rev2, ".");
-	}
-
-	/* If one of them is longer (not null), the shortest is the highest
-	 * ranked. */
-	if (tmp2 != NULL && tmp1 == NULL)
-		retval = -1;
-	else if (tmp2 == NULL && tmp1 != NULL)
-		retval = 1;
-
-done:
-	free(rev1orig);
-	free(rev2orig);
-	return (retval);
+	char *ptr1, *ptr2;
+	
+	ptr1 = revision1;
+	ptr2 = revision2; 
+	while (*ptr1 != '\0' && *ptr2 != '\0') {
+		if (*ptr1 > *ptr2)
+			return (1);
+		else if (*ptr1 < *ptr2)
+			return (-1);
+		ptr1++;
+		ptr2++;
+	};
+
+	if (*ptr1 != '\0' && *ptr2 == '\0')
+		return (1);
+	if (*ptr1 == '\0' && *ptr2 != '\0')
+		return (-1);
+	return (0);
 }
 
 /* Returns 0 if a rcsrev is not a trunk revision number. */


More information about the svn-src-projects mailing list