Jens Alfke avatar Jens Alfke committed dca9d1a

Oops, ordinals are supposed to be signed (the spec didn't specify one way or the other, but a form post I just discovered did.)

Comments (0)

Files changed (5)

     DoubleArray asDoubleArray() const;
     
     bool hasOrdinal() const         {return _hasOrdinal;}
-    uint16_t ordinal() const;
+    int16_t ordinal() const;
     bool hasName() const            {return _hasName;}
     std::string name() const;   // allocates heap space for the string!
     Data nameBytes() const;
         @return  True on success, false if the nested message is too large (which can only happen if the 'large' flag was set to false in the beginMessage call that created this Writer.) */
     bool end();
     
-    void setNextOrdinal(uint16_t o)             {_hasOrdinal = true; _ordinal = o;}
+    void setNextOrdinal(int16_t o)              {_hasOrdinal = true; _ordinal = o;}
     void setNextName(const std::string& n)      {_hasName = true; _name = n;}
     
     void addIndicator();
     bool _largeMessage;
     std::streampos _envelopeStartPos, _fieldStartPos, _dataStartPos;
     bool _hasOrdinal, _hasName;
-    uint16_t _ordinal;
+    int16_t _ordinal;
     std::string _name;
 };
 
 }
     
     
-uint16_t Field::ordinal() const {
+int16_t Field::ordinal() const {
     if (!_hasOrdinal)
         return 0;
-    return CFSwapInt16BigToHost(*(const uint16_t*)_data);
+    return (int16_t) CFSwapInt16BigToHost(*(const uint16_t*)_data);
 }
     
     
     
     // Write the optional ordinal and/or name:
     if (_hasOrdinal) {
-        uint16_t ordinal = CFSwapInt16HostToBig(_ordinal);
+        int16_t ordinal = (int16_t) CFSwapInt16HostToBig(_ordinal);
         _out.write((const char*)&ordinal, sizeof(ordinal));
         _hasOrdinal = false;
     }

test/TestFields.cpp

     Writer writer(out);
     writer.setNextOrdinal(0);
     writer.addInt(1234);
-    writer.setNextOrdinal(256);
+    writer.setNextOrdinal(5678);
     writer.addInt(1234);
-    writer.setNextOrdinal(65535);
+    writer.setNextOrdinal(32767);
+    writer.addInt(1234);
+    writer.setNextOrdinal(-32768);
+    writer.addInt(1234);
+    writer.setNextOrdinal(-1);
     writer.addInt(1234);
     writer.end();
     
     
     ASSERT_FALSE(++i == msg.end());
     EXPECT_TRUE(i->hasOrdinal());
-    EXPECT_EQ(256, i->ordinal());
+    EXPECT_EQ(5678, i->ordinal());
     
     ASSERT_FALSE(++i == msg.end());
     EXPECT_TRUE(i->hasOrdinal());
-    EXPECT_EQ(65535, i->ordinal());
+    EXPECT_EQ(32767, i->ordinal());
+    
+    ASSERT_FALSE(++i == msg.end());
+    EXPECT_TRUE(i->hasOrdinal());
+    EXPECT_EQ(-32768, i->ordinal());
+    
+    ASSERT_FALSE(++i == msg.end());
+    EXPECT_TRUE(i->hasOrdinal());
+    EXPECT_EQ(-1, i->ordinal());
     
     ASSERT_TRUE(++i == msg.end());
 }
     writer.setNextOrdinal(256);
     writer.setNextName("foo");
     writer.addInt(1234);
-    writer.setNextOrdinal(65535);
+    writer.setNextOrdinal(-32768);
     writer.setNextName(longestName);
     writer.addInt(1234);
     writer.end();
     
     ASSERT_FALSE(++i == msg.end());
     EXPECT_TRUE(i->hasOrdinal());
-    EXPECT_EQ(65535, i->ordinal());
+    EXPECT_EQ(-32768, i->ordinal());
     EXPECT_TRUE(i->hasName());
     EXPECT_EQ(longestName, i->name());
     
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.