From e471f5969eb79ebf74a362845e91431a920babcc Mon Sep 17 00:00:00 2001 From: Eric Dejouhanet Date: Sat, 31 Aug 2024 14:25:00 +0200 Subject: [PATCH 1/3] fix(indi-mgen): work around C++14 out-of-bounds warnings. --- indi-mgen/mgen.h | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/indi-mgen/mgen.h b/indi-mgen/mgen.h index d641add94..c7b6e9077 100644 --- a/indi-mgen/mgen.h +++ b/indi-mgen/mgen.h @@ -75,8 +75,26 @@ class IOError : std::exception /** \brief One word in the I/O protocol */ typedef unsigned char IOByte; -/** \brief A buffer of protocol words */ -typedef std::vector IOBuffer; +/** \brief A buffer of protocol words + * + * Those three constructors are implemented here to work around C++14 warnings about out-of-bounds copies on std::vector + */ +class IOBuffer : public std::vector +{ + public: + IOBuffer(IOBuffer const &b): std::vector(b.size()) + { + assign(b.begin(),b.end()); + } + IOBuffer(std::initializer_list const &b): std::vector(b.size()) + { + assign(b.begin(),b.end()); + } + IOBuffer(std::size_t s = 0): std::vector(s) + { + /* no-op */ + } +}; /** \internal Logging helpers */ /** @{ */ From ecad50ea7dd6d33908f4542e19a47fe4790dd6d8 Mon Sep 17 00:00:00 2001 From: Eric Dejouhanet Date: Sat, 31 Aug 2024 17:53:35 +0200 Subject: [PATCH 2/3] fix(indi-ahp-xc): silence warnings by allocating placeholders with their real size. --- indi-ahp-xc/indi_ahp_xc.cpp | 53 +++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/indi-ahp-xc/indi_ahp_xc.cpp b/indi-ahp-xc/indi_ahp_xc.cpp index eee7a5f70..e4dee661b 100644 --- a/indi-ahp-xc/indi_ahp_xc.cpp +++ b/indi-ahp-xc/indi_ahp_xc.cpp @@ -633,43 +633,44 @@ AHP_XC::AHP_XC() IntegrationRequest = 0.0; InIntegration = false; - autocorrelationsB = static_cast(malloc(1)); - crosscorrelationsB = static_cast(malloc(1)); - plotB = static_cast(malloc(1)); + // These allocations are uninitialised placeholders - lineStatsN = static_cast(malloc(1)); - lineStatsNP = static_cast(malloc(1)); + autocorrelationsB = static_cast(malloc(sizeof(IBLOB))); + crosscorrelationsB = static_cast(malloc(sizeof(IBLOB))); + plotB = static_cast(malloc(sizeof(IBLOB))); - lineEnableS = static_cast(malloc(1)); - lineEnableSP = static_cast(malloc(1)); + lineStatsN = static_cast(malloc(sizeof(INumber))); + lineStatsNP = static_cast(malloc(sizeof(INumberVectorProperty))); - linePowerS = static_cast(malloc(1)); - linePowerSP = static_cast(malloc(1)); + lineEnableS = static_cast(malloc(sizeof(ISwitch))); + lineEnableSP = static_cast(malloc(sizeof(ISwitchVectorProperty))); - lineActiveEdgeS = static_cast(malloc(1)); - lineActiveEdgeSP = static_cast(malloc(1)); + linePowerS = static_cast(malloc(sizeof(ISwitch))); + linePowerSP = static_cast(malloc(sizeof(ISwitchVectorProperty))); - lineEdgeTriggerS = static_cast(malloc(1)); - lineEdgeTriggerSP = static_cast(malloc(1)); + lineActiveEdgeS = static_cast(malloc(sizeof(ISwitch))); + lineActiveEdgeSP = static_cast(malloc(sizeof(ISwitchVectorProperty))); - lineLocationN = static_cast(malloc(1)); - lineLocationNP = static_cast(malloc(1)); + lineEdgeTriggerS = static_cast(malloc(sizeof(ISwitch))); + lineEdgeTriggerSP = static_cast(malloc(sizeof(ISwitchVectorProperty))); - lineDelayN = static_cast(malloc(1)); - lineDelayNP = static_cast(malloc(1)); + lineLocationN = static_cast(malloc(sizeof(INumber))); + lineLocationNP = static_cast(malloc(sizeof(INumberVectorProperty))); - correlationsN = static_cast(malloc(1)); + lineDelayN = static_cast(malloc(sizeof(INumber))); + lineDelayNP = static_cast(malloc(sizeof(INumberVectorProperty))); - autocorrelations_str = static_cast(malloc(1)); - crosscorrelations_str = static_cast(malloc(1)); - plot_str = static_cast(malloc(1)); + correlationsN = static_cast(malloc(sizeof(INumber))); - framebuffer = static_cast(malloc(1)); - totalcounts = static_cast(malloc(1)); - totalcorrelations = static_cast(malloc(1)); - delay = static_cast(malloc(1)); - baselines = static_cast(malloc(1)); + autocorrelations_str = static_cast(malloc(sizeof(dsp_stream_p))); + crosscorrelations_str = static_cast(malloc(sizeof(dsp_stream_p))); + plot_str = static_cast(malloc(sizeof(dsp_stream_p))); + framebuffer = static_cast(malloc(sizeof(double))); + totalcounts = static_cast(malloc(sizeof(double))); + totalcorrelations = static_cast(malloc(sizeof(ahp_xc_correlation))); + delay = static_cast(malloc(sizeof(double))); + baselines = static_cast(malloc(sizeof(baseline))); } bool AHP_XC::Disconnect() From 6f5d40e8a0485358abb3dac78adba7b6b8620968 Mon Sep 17 00:00:00 2001 From: Eric Dejouhanet Date: Sat, 31 Aug 2024 18:03:53 +0200 Subject: [PATCH 3/3] fix(indi-pentax): fix calloc argument order. --- indi-pentax/pentax_ccd.cpp | 2 +- indi-pentax/pktriggercord_ccd.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/indi-pentax/pentax_ccd.cpp b/indi-pentax/pentax_ccd.cpp index aa44fc419..f08917cd0 100644 --- a/indi-pentax/pentax_ccd.cpp +++ b/indi-pentax/pentax_ccd.cpp @@ -504,7 +504,7 @@ bool PentaxCCD::StopStreaming() ISwitch * PentaxCCD::create_switch(const char * basestr, std::vector options, int setidx) { - ISwitch * sw = static_cast(calloc(sizeof(ISwitch), options.size())); + ISwitch * sw = static_cast(calloc(options.size(), sizeof(ISwitch))); ISwitch * one_sw = sw; char sw_name[MAXINDINAME]; diff --git a/indi-pentax/pktriggercord_ccd.cpp b/indi-pentax/pktriggercord_ccd.cpp index 4cdddd7f0..6b207957b 100644 --- a/indi-pentax/pktriggercord_ccd.cpp +++ b/indi-pentax/pktriggercord_ccd.cpp @@ -706,7 +706,7 @@ bool PkTriggerCordCCD::grabImage() ISwitch * PkTriggerCordCCD::create_switch(const char * basestr, string options[], size_t numOptions, int setidx) { - ISwitch * sw = static_cast(calloc(sizeof(ISwitch), numOptions)); + ISwitch * sw = static_cast(calloc(numOptions, sizeof(ISwitch))); ISwitch * one_sw = sw; char sw_name[MAXINDINAME];