From bb9a897dcf799005e1febd8311f2a2c64cc31f81 Mon Sep 17 00:00:00 2001 From: Eric Date: Wed, 20 May 2020 17:34:45 -0400 Subject: [PATCH] Fix clang10 warnings in market data --- src/lib/md/MDConsumerHandle.cpp | 12 ++++-------- src/lib/md/MDConsumerHandle.h | 2 ++ src/lib/md/MDProducer.cpp | 5 +++++ src/lib/md/test/Co2TestInstrument.cpp | 10 ++++++++++ 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/lib/md/MDConsumerHandle.cpp b/src/lib/md/MDConsumerHandle.cpp index 442473281..b3e239e1f 100644 --- a/src/lib/md/MDConsumerHandle.cpp +++ b/src/lib/md/MDConsumerHandle.cpp @@ -12,13 +12,11 @@ using small_vector = boost::container::small_vector; namespace bts { namespace md { -MDConsumerHandle::MDConsumerHandle() { - memset(this, 0, sizeof(MDConsumerHandle)); - _type = HANDLETYPE_VOID; +MDConsumerHandle::MDConsumerHandle() : _type(HANDLETYPE_VOID), book() { + // value initializing 'book' zeroes the union static_assert(sizeof(MDConsumerHandle) <= 40, ""); } -MDConsumerHandle::MDConsumerHandle(const std::shared_ptr& def) { - memset(this, 0, sizeof(MDConsumerHandle)); +MDConsumerHandle::MDConsumerHandle(const std::shared_ptr& def) : _type(HANDLETYPE_VOID), book() { synthetic.def = def; _type = HANDLETYPE_SYNTHETIC; for(size_t x = 0; x < def->legs.size(); ++x) { @@ -26,9 +24,7 @@ MDConsumerHandle::MDConsumerHandle(const std::shared_ptr def; }; HandleType _type; + // NOTE: If we ever have to add to this union + // it would be best to convert it to an std::variant() union { DepthHandle book; BBOHandle bbo; diff --git a/src/lib/md/MDProducer.cpp b/src/lib/md/MDProducer.cpp index c6eed6a42..3fb42354d 100644 --- a/src/lib/md/MDProducer.cpp +++ b/src/lib/md/MDProducer.cpp @@ -50,7 +50,12 @@ public: // Calculating the size for the variable sized entries is tricky ColdEntry* c_entry = new (_cold.add(ColdEntry::fixed_size() + security.size)) ColdEntry(security.size); +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wclass-memaccess" + // Security here is a variable sized structure (may be FixedFuture/FixedOption) + // So we have to memcpy to keep the extra fields memcpy(&c_entry->security, &security, security.size); +#pragma GCC diagnostic pop smapper.apply(c_entry->security); MDProducerHandle handle(_cold.header(), _hot.header(), *c_entry, h_entry, MDProducerChannel(*this)); diff --git a/src/lib/md/test/Co2TestInstrument.cpp b/src/lib/md/test/Co2TestInstrument.cpp index 0c2c2274a..b6e074adf 100644 --- a/src/lib/md/test/Co2TestInstrument.cpp +++ b/src/lib/md/test/Co2TestInstrument.cpp @@ -17,7 +17,12 @@ Co2TestInstrument::Co2TestInstrument(const std::string& symbol, SecurityType typ fsec.exchange = api::VENUE_BTS; _cold_buffer = std::shared_ptr(new uint8_t[ColdEntry::fixed_size() + fsec.size], std::default_delete()); _cold = new (_cold_buffer.get()) ColdEntry(fsec.size); +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wclass-memaccess" + // Security here is a variable sized structure (may be FixedFuture/FixedOption) + // So we have to memcpy to keep the extra fields memcpy(&_cold->security, &fsec, fsec.size); +#pragma GCC diagnostic pop }); } @@ -33,7 +38,12 @@ Co2TestInstrument::Co2TestInstrument(const Security& security, std::shared_ptr(new uint8_t[ColdEntry::fixed_size() + fsec.size], std::default_delete()); _cold = new (_cold_buffer.get()) ColdEntry(fsec.size); +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wclass-memaccess" + // Security here is a variable sized structure (may be FixedFuture/FixedOption) + // So we have to memcpy to keep the extra fields memcpy(&_cold->security, &fsec, fsec.size); +#pragma GCC diagnostic pop }); }