Browse Source

Fix invalid check in varint serialization

- Replace check for greater than to not equal 0
- Some comments improvements
Alexey Edelev 5 years ago
parent
commit
461a35ef50
1 changed files with 4 additions and 3 deletions
  1. 4 3
      src/protobuf/qprotobufobject_p.h

+ 4 - 3
src/protobuf/qprotobufobject_p.h

@@ -198,8 +198,8 @@ public:
         QByteArray result;
         //Reserve maximum required amount of bytes
         result.reserve(sizeof(V));
-        while (value > 0) {
-            //Put first 7 bits to result buffer and mark as not last
+        while (value != 0) {
+            //Put 7 bits to result buffer and mark as "not last"(0x80)
             result.append((value & 0x7F) | 0x80);
             //Devide values to chunks of 7 bits, move to next chunk
             value >>= 7;
@@ -211,10 +211,11 @@ public:
          * }
          */
 
-        //Mark last chunk as last or invalidate field in case if serialized result is empty
+        //Invalidate field in case if serialized result is empty
         if (result.size() == 0) {
             outFieldIndex = NotUsedFieldIndex;
         } else {
+            //Mark last chunk as last by removing(0x80)
             result.data()[result.size() - 1] &= ~0x80;
         }
         return result;