diff --git a/src/lib/md/MDProducer.cpp b/src/lib/md/MDProducer.cpp index 3635dfc58..4d4122d5b 100644 --- a/src/lib/md/MDProducer.cpp +++ b/src/lib/md/MDProducer.cpp @@ -141,6 +141,7 @@ MDProducerImpl& MDProducer::get_producer(const char* symbol, SecurityType type, MDProducerHandle MDProducer::add_security(const FixedSecurity& security) { bts_assert_d(strlen(security.symbol()) > 0); + bts_assert(security.size >= sizeof(FixedSecurity)); Mutex::scoped_lock lock(*_mutex); auto& impl = get_producer(security.symbol(), security.type, security.exchange); auto result = impl.add_security(security); diff --git a/src/lib/md/Shm/FixedSecurity.cpp b/src/lib/md/Shm/FixedSecurity.cpp index d0b11cbd0..67ded47e4 100644 --- a/src/lib/md/Shm/FixedSecurity.cpp +++ b/src/lib/md/Shm/FixedSecurity.cpp @@ -203,6 +203,9 @@ void convert_security(const FixedSecurity& source, Security* presult) { case SECURITYTYPE_SYNTHETIC: { const auto* psec = static_cast(&source); psec->deserialize(dest); + bts_assert(dest.id() == source.key); + bts_assert(dest.exchange() == source.exchange); + bts_assert(dest.symbol() == source.symbol()); break; } case SECURITYTYPE_STOCK: @@ -297,12 +300,25 @@ void convert_security(const Security& src, FixedSecurity& dest, bool set_securit } break; } + case SECURITYTYPE_SYNTHETIC: { + FixedSyntheticSecurity& synth = static_cast(dest); + bts_assert(synth.buffer_size() > 0); + // Due to how we create a FixedSecurity this FixedSecurity should already be populated + bts_assert(synth.leg_count() == (unsigned)src.synthetic().legs_size()); +#ifndef NDEBUG + { + Security temp; + static_cast(&dest)->deserialize(temp); + bts_assert_d(temp.SerializeAsString() == src.SerializeAsString()); + } +#endif + break; + } case SECURITYTYPE_STOCK: break; case SECURITYTYPE_UNSET: case SecurityType_INT_MAX_SENTINEL_DO_NOT_USE_: case SecurityType_INT_MIN_SENTINEL_DO_NOT_USE_: - default: - bts_assert(false); + bts_assert(false); } } diff --git a/src/lib/md/Shm/FixedSecurity.h b/src/lib/md/Shm/FixedSecurity.h index 8d34a4800..b52f36657 100644 --- a/src/lib/md/Shm/FixedSecurity.h +++ b/src/lib/md/Shm/FixedSecurity.h @@ -132,10 +132,11 @@ public: _buffer_size(sec.ByteSize()) { type = api::SECURITYTYPE_SYNTHETIC; - // you better have allocated me correctly! sec.SerializeToArray(buffer(), _buffer_size); + size = sizeof(FixedSyntheticSecurity) + _buffer_size; } uint32_t leg_count() const { return _leg_count; } + uint32_t buffer_size() const { return _buffer_size; } void deserialize(api::Security& dest) const { dest.ParseFromArray(buffer(), _buffer_size); @@ -223,7 +224,7 @@ void with_security(SecurityType type, size_t leg_count, const api::Security* psy // We could optimize this by using a fixed size stack buffer and only heap allocating if we exceed that // but in general FixedSynthetic is not performance sensitive std::vector buffer; - buffer.reserve(psynthetic->ByteSize()); + buffer.resize(psynthetic->ByteSize() + sizeof(FixedSyntheticSecurity)); auto* psec = new (&buffer[0]) FixedSyntheticSecurity(*psynthetic); cb(*psec); return; diff --git a/src/lib/md/relay/QueryServer.cpp b/src/lib/md/relay/QueryServer.cpp index bd4dc51ba..59427598d 100644 --- a/src/lib/md/relay/QueryServer.cpp +++ b/src/lib/md/relay/QueryServer.cpp @@ -151,7 +151,6 @@ public: auto id = _consumer.id(); _consumer.on_security([this,id](const Security&, MDConsumerHandle handle) { if (_consumer.id() == id) { - auto us = handle.get_usersymbol(); auto iter = _groups.find(handle.get_usersymbol()); bts_assert(iter != _groups.end()); const auto& pgroup = iter->second;