diff --git a/src/pubkey.h b/src/pubkey.h
--- a/src/pubkey.h
+++ b/src/pubkey.h
@@ -120,7 +120,7 @@
         s.write((char *)vch, len);
     }
     template <typename Stream> void Unserialize(Stream &s) {
-        unsigned int len = ::ReadCompactSize(s);
+        const unsigned int len(::ReadCompactSize(s));
         if (len <= SIZE) {
             s.read((char *)vch, len);
             if (len != size()) {
@@ -128,10 +128,7 @@
             }
         } else {
             // invalid pubkey, skip available data
-            char dummy;
-            while (len--) {
-                s.read(&dummy, 1);
-            }
+            s.ignore(len);
             Invalidate();
         }
     }