Add a 'found' field to pb_extension_t.
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>
Sat, 5 Apr 2014 08:11:05 +0000 (11:11 +0300)
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>
Sat, 5 Apr 2014 08:11:05 +0000 (11:11 +0300)
Update issue 112
Status: FixedInGit

pb.h
pb_decode.c
tests/extensions/decode_extensions.c
tests/splint/splint.rc

diff --git a/pb.h b/pb.h
index 6f84385..63d313d 100644 (file)
--- a/pb.h
+++ b/pb.h
@@ -341,6 +341,10 @@ struct _pb_extension_t {
      * If this extension does not match a field, the next handler is
      * automatically called. */
     pb_extension_t *next;
+
+    /* The decoder sets this to true if the extension was found.
+     * Ignored for encoding. */
+    bool found;
 };
 
 /* Memory allocation functions to use. You can define pb_realloc and
index d8ac9ee..9a48c60 100644 (file)
@@ -670,7 +670,6 @@ static bool checkreturn default_extension_decoder(pb_istream_t *stream,
 {
     const pb_field_t *field = (const pb_field_t*)extension->type->arg;
     pb_field_iterator_t iter;
-    bool dummy;
     
     if (field->tag != tag)
         return true;
@@ -681,7 +680,7 @@ static bool checkreturn default_extension_decoder(pb_istream_t *stream,
     iter.required_field_index = 0;
     iter.dest_struct = extension->dest;
     iter.pData = extension->dest;
-    iter.pSize = &dummy;
+    iter.pSize = &extension->found;
     
     return decode_field(stream, wire_type, &iter);
 }
index f8ebbde..e437438 100644 (file)
@@ -49,7 +49,9 @@ int main(int argc, char **argv)
     }
 
     /* Check that the extensions decoded properly */
+    TEST(ext1.found)
     TEST(extensionfield1 == 12345)
+    TEST(ext2.found)
     TEST(strcmp(extensionfield2.test1, "test") == 0)
     TEST(extensionfield2.test2 == 54321)
     
index c77e210..421f567 100644 (file)
@@ -27,6 +27,7 @@
 -dependenttrans
 -kepttrans
 -branchstate
+-immediatetrans
 
 # These tests give false positives, compiler typically has
 # better warnings for these.