Updated Branches:
  refs/heads/master d919a7656 -> 1715fcda6

Fixes to CFCVersion.c


Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/1715fcda
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/1715fcda
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/1715fcda

Branch: refs/heads/master
Commit: 1715fcda698c540270b3d6e0956560400c9ad993
Parents: d919a76
Author: Nick Wellnhofer <[email protected]>
Authored: Sun Jan 27 02:48:13 2013 +0100
Committer: Nick Wellnhofer <[email protected]>
Committed: Sun Jan 27 02:48:13 2013 +0100

----------------------------------------------------------------------
 clownfish/compiler/perl/t/052-version.t |    5 ++++-
 clownfish/compiler/src/CFCVersion.c     |   20 +++++++++++---------
 2 files changed, 15 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/1715fcda/clownfish/compiler/perl/t/052-version.t
----------------------------------------------------------------------
diff --git a/clownfish/compiler/perl/t/052-version.t 
b/clownfish/compiler/perl/t/052-version.t
index e9ecd4a..1e96bb8 100644
--- a/clownfish/compiler/perl/t/052-version.t
+++ b/clownfish/compiler/perl/t/052-version.t
@@ -16,10 +16,11 @@
 use strict;
 use warnings;
 
-use Test::More tests => 9;
+use Test::More tests => 11;
 use Clownfish::CFC;
 
 my $v3_2_1   = Clownfish::CFC::Model::Version->new( vstring => 'v3.2.1' );
+my $v3_2     = Clownfish::CFC::Model::Version->new( vstring => 'v3.2' );
 my $v3_3     = Clownfish::CFC::Model::Version->new( vstring => 'v3.3' );
 my $v3_2_0   = Clownfish::CFC::Model::Version->new( vstring => 'v3.2.0' );
 my $v3_2_1_0 = Clownfish::CFC::Model::Version->new( vstring => 'v3.2.1.0' );
@@ -33,6 +34,8 @@ is( $v3_2_1->compare_to($v3_2_1_0), 0,  "ignore zeroes in 
compare_to" );
 is( $v3_2_1_0->compare_to($v3_2_1), 0,  "ignore zeroes in compare_to" );
 is( $v3_2_1->compare_to($v3_3),     -1, "compare_to A < B_fewer_digits" );
 is( $v3_3->compare_to($v3_2_1),     1,  "compare_to A_fewer_digits > B" );
+is( $v3_2_1->compare_to($v3_2),     1,  "compare_to A < B_fewer_digits" );
+is( $v3_2->compare_to($v3_2_1),     -1, "compare_to A_fewer_digits > B" );
 is( $v3_2_1->compare_to($v3_2_0),   1,  "compare_to A > B" );
 is( $v3_2_0->compare_to($v3_2_1),   -1, "compare_to A < B" );
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/1715fcda/clownfish/compiler/src/CFCVersion.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCVersion.c 
b/clownfish/compiler/src/CFCVersion.c
index 462d97c..6c2b88a 100644
--- a/clownfish/compiler/src/CFCVersion.c
+++ b/clownfish/compiler/src/CFCVersion.c
@@ -59,7 +59,10 @@ CFCVersion_init(CFCVersion *self, const char *vstring) {
     self->num_numbers = 0;
     self->numbers = (uint32_t*)CALLOCATE(1, sizeof(uint32_t));
     while (1) {
-        if (!isdigit(*vstring)) {
+        if (isdigit(*vstring)) {
+            num = num * 10 + *vstring - '0';
+        }
+        else {
             if (*vstring != 0 && *vstring != '.') {
                 CFCBase_decref((CFCBase*)self);
                 CFCUtil_die("Bad version string: '%s'", self->vstring);
@@ -72,7 +75,6 @@ CFCVersion_init(CFCVersion *self, const char *vstring) {
             }
             num = 0;
         }
-        num = num * 10 + *vstring - '0';
         vstring++;
     }
 
@@ -89,15 +91,15 @@ CFCVersion_destroy(CFCVersion *self) {
 int
 CFCVersion_compare_to(CFCVersion *self, CFCVersion *other) {
     for (size_t i = 0;
-         i < self->num_numbers && i < other->num_numbers;
+         i < self->num_numbers || i < other->num_numbers;
          i++
         ) {
-        int32_t my_number = i >= self->num_numbers
-                            ? 0
-                            : self->numbers[i];
-        int32_t other_number = i >= other->num_numbers
-                               ? 0
-                               : other->numbers[i];
+        uint32_t my_number = i >= self->num_numbers
+                             ? 0
+                             : self->numbers[i];
+        uint32_t other_number = i >= other->num_numbers
+                                ? 0
+                                : other->numbers[i];
         if (my_number > other_number) {
             return 1;
         }

Reply via email to