summaryrefslogtreecommitdiffstats
path: root/generic/tclPkg.c
diff options
context:
space:
mode:
authorandreas_kupries <akupries@shaw.ca>2006-09-28 20:54:45 (GMT)
committerandreas_kupries <akupries@shaw.ca>2006-09-28 20:54:45 (GMT)
commit858a806396de6a90554a6ebd0ce288b554f61ac7 (patch)
treeebfbd2f782bca8a075cfad1ed8604686266384db /generic/tclPkg.c
parent341cfa533b51784f8cb9183ec8e2ed6fe6a26e32 (diff)
downloadtcl-858a806396de6a90554a6ebd0ce288b554f61ac7.zip
tcl-858a806396de6a90554a6ebd0ce288b554f61ac7.tar.gz
tcl-858a806396de6a90554a6ebd0ce288b554f61ac7.tar.bz2
* generic/tclPkg.c (CompareVersions): Bugfix. Check string lengths
* tests/pkg.test: before comparison. The shorter string is the smaller number. Added testcases as well. Interestingly all existing test cases for vcompare compared numbers of the same length with each other. See [SF Tcl Bug 1563836].
Diffstat (limited to 'generic/tclPkg.c')
-rw-r--r--generic/tclPkg.c26
1 files changed, 17 insertions, 9 deletions
diff --git a/generic/tclPkg.c b/generic/tclPkg.c
index 25c044c..d2952a0 100644
--- a/generic/tclPkg.c
+++ b/generic/tclPkg.c
@@ -10,7 +10,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclPkg.c,v 1.18 2006/09/28 15:10:25 dgp Exp $
+ * RCS: @(#) $Id: tclPkg.c,v 1.19 2006/09/28 20:54:45 andreas_kupries Exp $
*
* TIP #268.
* Heavily rewritten to handle the extend version numbers, and extended
@@ -1383,18 +1383,26 @@ CompareVersions(
e2 = s2; while ((*e2 != 0) && (*e2 != ' ')) { e2 ++; }
/*
- * s1 .. e1 and s2 .. e2 now bracket the numbers to compare.
- * Insert terminators, compare, and restore actual contents.
+ * s1 .. e1 and s2 .. e2 now bracket the numbers to compare. Insert
+ * terminators, compare, and restore actual contents. First however
+ * another shortcut. Compare lengths. Shorter string is smaller
+ * number! Thus we strcmp only strings of identical length.
*/
- o1 = *e1 ; *e1 = '\0';
- o2 = *e2 ; *e2 = '\0';
+ if ((e1-s1) < (e2-s2)) {
+ res = -1;
+ } else if ((e2-s2) < (e1-s1)) {
+ res = 1;
+ } else {
+ o1 = *e1 ; *e1 = '\0';
+ o2 = *e2 ; *e2 = '\0';
- res = strcmp (s1, s2);
- res = (res < 0) ? -1 : (res ? 1 : 0);
+ res = strcmp (s1, s2);
+ res = (res < 0) ? -1 : (res ? 1 : 0);
- *e1 = o1;
- *e2 = o2;
+ *e1 = o1;
+ *e2 = o2;
+ }
/*
* Stop comparing segments when a difference has been found. Here we