From dd55ddea953fdfd3dd09e49112738a85bd6d780d Mon Sep 17 00:00:00 2001 From: Gioacchino Mazzurco Date: Tue, 28 Aug 2018 15:20:41 +0200 Subject: [PATCH] Add more consistency checks to serialization code As suggested by Cyril --- libretroshare/src/serialiser/rsserializer.cc | 29 ++++++++++++++++++++ libretroshare/src/serialiser/rsserializer.h | 6 +--- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/libretroshare/src/serialiser/rsserializer.cc b/libretroshare/src/serialiser/rsserializer.cc index 3905f2cac..c1385fddf 100644 --- a/libretroshare/src/serialiser/rsserializer.cc +++ b/libretroshare/src/serialiser/rsserializer.cc @@ -26,6 +26,7 @@ #include "util/rsprint.h" #include "serialiser/rsserializer.h" #include "serialiser/rstypeserializer.h" +#include "util/stacktrace.h" const SerializationFlags RsGenericSerializer::SERIALIZATION_FLAG_NONE ( 0x0000 ); const SerializationFlags RsGenericSerializer::SERIALIZATION_FLAG_CONFIG ( 0x0001 ); @@ -241,3 +242,31 @@ RsItem *RsRawSerialiser::deserialise(void *data, uint32_t *pktsize) return item; } + +RsGenericSerializer::SerializeContext::SerializeContext( + uint8_t* data, uint32_t size, SerializationFlags flags, + RsJson::AllocatorType* allocator ) : + mData(data), mSize(size), mOffset(0), mOk(true), mFlags(flags), + mJson(rapidjson::kObjectType, allocator) +{ + if(data) + { + if(size == 0) + { + std::cerr << __PRETTY_FUNCTION__ << " data passed without " + << "size! This make no sense report to developers!" + << std::endl; + print_stacktrace(); + } + + if(flags & SERIALIZATION_FLAG_YIELDING) + { + std::cerr << __PRETTY_FUNCTION__ << " Attempt to create a " + << "binary serialization context with " + << "SERIALIZATION_FLAG_YIELDING! " + << "This make no sense report to developers!" + << std::endl; + print_stacktrace(); + } + } +} diff --git a/libretroshare/src/serialiser/rsserializer.h b/libretroshare/src/serialiser/rsserializer.h index 09803eaa6..40ccc35e9 100644 --- a/libretroshare/src/serialiser/rsserializer.h +++ b/libretroshare/src/serialiser/rsserializer.h @@ -159,8 +159,6 @@ struct RsItem; -#define SERIALIZE_ERROR() std::cerr << __PRETTY_FUNCTION__ << " : " - // This is the base class for serializers. class RsSerialType @@ -222,9 +220,7 @@ struct RsGenericSerializer : RsSerialType SerializeContext( uint8_t* data = nullptr, uint32_t size = 0, SerializationFlags flags = SERIALIZATION_FLAG_NONE, - RsJson::AllocatorType* allocator = nullptr) : - mData(data), mSize(size), mOffset(0), mOk(true), mFlags(flags), - mJson(rapidjson::kObjectType, allocator) {} + RsJson::AllocatorType* allocator = nullptr); RS_DEPRECATED SerializeContext( uint8_t *data, uint32_t size, SerializationFormat format,