diff --git a/source/Makefile.mk b/source/Makefile.mk index 2d1988576..5dc7140d7 100644 --- a/source/Makefile.mk +++ b/source/Makefile.mk @@ -180,7 +180,9 @@ BASE_FLAGS += -Wmissing-declarations -Wredundant-decls BASE_FLAGS += -Wshadow -Wundef -Wuninitialized -Wunused BASE_FLAGS += -Wstrict-aliasing -fstrict-aliasing BASE_FLAGS += -Wstrict-overflow -fstrict-overflow -BASE_FLAGS += -Wduplicated-branches -Wduplicated-cond -Wnull-dereference +BASE_FLAGS += -Wduplicated-branches -Wduplicated-cond -Wnull-dereference +BASE_FLAGS += -Wformat-truncation=2 -Wformat-overflow=2 +BASE_FLAGS += -Wstringop-overflow=4 -Wstringop-truncation CFLAGS += -Winit-self -Wjump-misses-init -Wmissing-prototypes -Wnested-externs -Wstrict-prototypes -Wwrite-strings CXXFLAGS += -Wc++0x-compat -Wc++11-compat CXXFLAGS += -Wnon-virtual-dtor -Woverloaded-virtual diff --git a/source/backend/engine/CarlaEngineNative.cpp b/source/backend/engine/CarlaEngineNative.cpp index 473449c76..72ce4a1af 100644 --- a/source/backend/engine/CarlaEngineNative.cpp +++ b/source/backend/engine/CarlaEngineNative.cpp @@ -427,7 +427,7 @@ protected: { const CarlaScopedLocale csl; - std::snprintf(tmpBuf, STR_MAX, "%f\n", newSampleRate); + std::snprintf(tmpBuf, STR_MAX, "%.12g\n", newSampleRate); } if (fUiServer.writeMessage(tmpBuf)) @@ -537,7 +537,7 @@ protected: std::snprintf(tmpBuf, STR_MAX, "PARAMVAL_%u:%i\n", pluginId, i); CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),); - std::snprintf(tmpBuf, STR_MAX, "%f\n", static_cast(plugin->getInternalParameterValue(i))); + std::snprintf(tmpBuf, STR_MAX, "%.12g\n", static_cast(plugin->getInternalParameterValue(i))); CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),); fUiServer.flushMessages(); @@ -589,7 +589,7 @@ protected: std::snprintf(tmpBuf, STR_MAX, "PARAMETER_RANGES_%i:%i\n", pluginId, i); CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),); - std::snprintf(tmpBuf, STR_MAX, "%f:%f:%f:%f:%f:%f\n", + std::snprintf(tmpBuf, STR_MAX, "%.12g:%.12g:%.12g:%.12g:%.12g:%.12g\n", static_cast(paramRanges.def), static_cast(paramRanges.min), static_cast(paramRanges.max), @@ -601,7 +601,7 @@ protected: std::snprintf(tmpBuf, STR_MAX, "PARAMVAL_%u:%u\n", pluginId, i); CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),); - std::snprintf(tmpBuf, STR_MAX, "%f\n", static_cast(plugin->getParameterValue(i))); + std::snprintf(tmpBuf, STR_MAX, "%.12g\n", static_cast(plugin->getParameterValue(i))); CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),); } @@ -780,7 +780,7 @@ protected: { const CarlaScopedLocale csl; - std::snprintf(tmpBuf, STR_MAX, "%f\n", static_cast(valuef)); + std::snprintf(tmpBuf, STR_MAX, "%.12g\n", static_cast(valuef)); } CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),); @@ -837,7 +837,7 @@ protected: CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage("sample-rate\n"),); { const CarlaScopedLocale csl; - std::snprintf(tmpBuf, STR_MAX, "%f\n", pData->sampleRate); + std::snprintf(tmpBuf, STR_MAX, "%.12g\n", pData->sampleRate); } CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),); @@ -1380,7 +1380,7 @@ protected: // send engine info CARLA_SAFE_ASSERT_RETURN(fUiServer.writeAndFixMessage("runtime-info"),); - std::snprintf(tmpBuf, STR_MAX, "%f:0\n", static_cast(getDSPLoad())); + std::snprintf(tmpBuf, STR_MAX, "%.12g:0\n", static_cast(getDSPLoad())); CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),); fUiServer.flushMessages(); @@ -1398,7 +1398,7 @@ protected: timeInfo.bbt.beat, static_cast(timeInfo.bbt.tick + 0.5)); CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),); - std::snprintf(tmpBuf, STR_MAX, "%f\n", timeInfo.bbt.beatsPerMinute); + std::snprintf(tmpBuf, STR_MAX, "%.12g\n", timeInfo.bbt.beatsPerMinute); CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),); } else @@ -1420,7 +1420,7 @@ protected: std::snprintf(tmpBuf, STR_MAX, "PEAKS_%i\n", i); CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),); - std::snprintf(tmpBuf, STR_MAX, "%f:%f:%f:%f\n", + std::snprintf(tmpBuf, STR_MAX, "%.12g:%.12g:%.12g:%.12g\n", static_cast(plugData.peaks[0]), static_cast(plugData.peaks[1]), static_cast(plugData.peaks[2]), @@ -1436,7 +1436,7 @@ protected: std::snprintf(tmpBuf, STR_MAX, "PARAMVAL_%u:%u\n", i, j); CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),); - std::snprintf(tmpBuf, STR_MAX, "%f\n", static_cast(plugin->getParameterValue(j))); + std::snprintf(tmpBuf, STR_MAX, "%.12g\n", static_cast(plugin->getParameterValue(j))); CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),); fUiServer.flushMessages(); diff --git a/source/backend/engine/CarlaEnginePorts.cpp b/source/backend/engine/CarlaEnginePorts.cpp index 5ba103d64..a4e971ffd 100644 --- a/source/backend/engine/CarlaEnginePorts.cpp +++ b/source/backend/engine/CarlaEnginePorts.cpp @@ -102,8 +102,8 @@ void CarlaEngineCVPort::setRange(const float min, const float max) noexcept { const CarlaScopedLocale csl; - std::snprintf(strBufMin, STR_MAX-1, "%f", static_cast(min)); - std::snprintf(strBufMax, STR_MAX-1, "%f", static_cast(max)); + std::snprintf(strBufMin, STR_MAX-1, "%.12g", static_cast(min)); + std::snprintf(strBufMax, STR_MAX-1, "%.12g", static_cast(max)); } setMetaData(LV2_CORE__minimum, strBufMin, ""); diff --git a/source/backend/plugin/CarlaPlugin.cpp b/source/backend/plugin/CarlaPlugin.cpp index fd12f8fb9..97c93b5ad 100644 --- a/source/backend/plugin/CarlaPlugin.cpp +++ b/source/backend/plugin/CarlaPlugin.cpp @@ -1771,7 +1771,7 @@ void CarlaPlugin::setParameterMappedRange(const uint32_t parameterId, const floa char strBuf[STR_MAX+1]; carla_zeroChars(strBuf, STR_MAX+1); - std::snprintf(strBuf, STR_MAX, "%f:%f", static_cast(minimum), static_cast(maximum)); + std::snprintf(strBuf, STR_MAX, "%.12g:%.12g", static_cast(minimum), static_cast(maximum)); #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH pData->engine->callback(sendCallback, sendOsc, diff --git a/source/backend/plugin/CarlaPluginBridge.cpp b/source/backend/plugin/CarlaPluginBridge.cpp index 9f4377f9c..380710909 100644 --- a/source/backend/plugin/CarlaPluginBridge.cpp +++ b/source/backend/plugin/CarlaPluginBridge.cpp @@ -583,7 +583,7 @@ public: if (waitForParameterText()) return true; - std::snprintf(strBuf, STR_MAX, "%f", static_cast(fParams[parameterId].value)); + std::snprintf(strBuf, STR_MAX, "%.12g", static_cast(fParams[parameterId].value)); return false; } diff --git a/source/backend/plugin/CarlaPluginLADSPADSSI.cpp b/source/backend/plugin/CarlaPluginLADSPADSSI.cpp index 01781474f..b2833133b 100644 --- a/source/backend/plugin/CarlaPluginLADSPADSSI.cpp +++ b/source/backend/plugin/CarlaPluginLADSPADSSI.cpp @@ -3111,25 +3111,25 @@ private: static bool _getSeparatedParameterNameOrUnitImpl(const char* const paramName, char* const strBuf, const bool wantName, const bool useBracket) noexcept { - const char* const sepBracketStart(std::strstr(paramName, useBracket ? " [" : " (")); + const char* const sepBracketStart = std::strstr(paramName, useBracket ? " [" : " ("); if (sepBracketStart == nullptr) return false; - const char* const sepBracketEnd(std::strstr(sepBracketStart, useBracket ? "]" : ")")); + const char* const sepBracketEnd = std::strstr(sepBracketStart, useBracket ? "]" : ")"); if (sepBracketEnd == nullptr) return false; - const std::size_t unitSize(static_cast(sepBracketEnd-sepBracketStart-2)); + const std::size_t unitSize = static_cast(sepBracketEnd-sepBracketStart-2); if (unitSize > 7) // very unlikely to have such big unit return false; - const std::size_t sepIndex(std::strlen(paramName)-unitSize-3); + const std::size_t sepIndex = std::strlen(paramName)-unitSize-3; // just in case - if (sepIndex+2 >= STR_MAX) + if (sepIndex > STR_MAX-3) return false; if (wantName) diff --git a/source/backend/plugin/CarlaPluginLV2.cpp b/source/backend/plugin/CarlaPluginLV2.cpp index afd635af9..54f40c47e 100644 --- a/source/backend/plugin/CarlaPluginLV2.cpp +++ b/source/backend/plugin/CarlaPluginLV2.cpp @@ -478,7 +478,7 @@ public: char sampleRateStr[32]; { const CarlaScopedLocale csl; - std::snprintf(sampleRateStr, 31, "%f", kEngine->getSampleRate()); + std::snprintf(sampleRateStr, 31, "%.12g", kEngine->getSampleRate()); } sampleRateStr[31] = '\0'; @@ -1580,7 +1580,7 @@ public: if (! fPipeServer.writeMessage(tmpBuf)) return; - std::snprintf(tmpBuf, 0xff, "%f\n", static_cast(pData->engine->getOptions().uiScale)); + std::snprintf(tmpBuf, 0xff, "%.12g\n", static_cast(pData->engine->getOptions().uiScale)); if (! fPipeServer.writeMessage(tmpBuf)) return; @@ -1611,7 +1611,7 @@ public: if (! fPipeServer.writeMessage(tmpBuf)) return; - std::snprintf(tmpBuf, 0xff, "%f\n", static_cast(getParameterValue(i))); + std::snprintf(tmpBuf, 0xff, "%.12g\n", static_cast(getParameterValue(i))); if (! fPipeServer.writeMessage(tmpBuf)) return; } diff --git a/source/backend/plugin/CarlaPluginVST2.cpp b/source/backend/plugin/CarlaPluginVST2.cpp index 2e6379e05..e13ef0dd4 100644 --- a/source/backend/plugin/CarlaPluginVST2.cpp +++ b/source/backend/plugin/CarlaPluginVST2.cpp @@ -339,7 +339,7 @@ public: dispatcher(effGetParamDisplay, static_cast(parameterId), 0, strBuf); if (strBuf[0] == '\0') - std::snprintf(strBuf, STR_MAX, "%f", static_cast(getParameterValue(parameterId))); + std::snprintf(strBuf, STR_MAX, "%.12g", static_cast(getParameterValue(parameterId))); return true; } diff --git a/source/modules/rtaudio/RtAudio.h b/source/modules/rtaudio/RtAudio.h index 289e254c1..4f323b01d 100644 --- a/source/modules/rtaudio/RtAudio.h +++ b/source/modules/rtaudio/RtAudio.h @@ -113,7 +113,7 @@ static const RtAudioFormat RTAUDIO_FLOAT64 = 0x20; // Normalized between plus/mi open the input and/or output stream device(s) for exclusive use. Note that this is not possible with all supported audio APIs. - If the RTAUDIO_SCHEDULE_REALTIME flag is set, RtAudio will attempt + If the RTAUDIO_SCHEDULE_REALTIME flag is set, RtAudio will attempt to select realtime scheduling (round-robin) for the callback thread. If the RTAUDIO_ALSA_USE_DEFAULT flag is set, RtAudio will attempt to @@ -347,7 +347,7 @@ class RTAUDIO_DLL_PUBLIC RtAudio open the input and/or output stream device(s) for exclusive use. Note that this is not possible with all supported audio APIs. - If the RTAUDIO_SCHEDULE_REALTIME flag is set, RtAudio will attempt + If the RTAUDIO_SCHEDULE_REALTIME flag is set, RtAudio will attempt to select realtime scheduling (round-robin) for the callback thread. The \c priority parameter will only be used if the RTAUDIO_SCHEDULE_REALTIME flag is set. It defines the thread's realtime priority. @@ -416,7 +416,7 @@ class RTAUDIO_DLL_PUBLIC RtAudio /*! This function performs a system query of available devices each time it is called, thus supporting devices connected \e after instantiation. If - a system error occurs during processing, a warning will be issued. + a system error occurs during processing, a warning will be issued. */ unsigned int getDeviceCount( void ); @@ -483,7 +483,7 @@ class RTAUDIO_DLL_PUBLIC RtAudio from within the callback function. \param options An optional pointer to a structure containing various global stream options, including a list of OR'ed RtAudioStreamFlags - and a suggested number of stream buffers that can be used to + and a suggested number of stream buffers that can be used to control stream latency. More buffers typically result in more robust performance, though at a cost of greater latency. If a value of zero is specified, a system-specific median value is @@ -658,7 +658,9 @@ class S24 { return *this; } +#if defined(__GNUC__) && __GNUC__ < 8 S24( const S24& v ) { *this = v; } +#endif S24( const double& d ) { *this = (int) d; } S24( const float& f ) { *this = (int) f; } S24( const signed short& s ) { *this = (int) s; } @@ -792,7 +794,7 @@ protected: "warning" message is reported and FAILURE is returned. A successful probe is indicated by a return value of SUCCESS. */ - virtual bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels, + virtual bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels, unsigned int firstChannel, unsigned int sampleRate, RtAudioFormat format, unsigned int *bufferSize, RtAudio::StreamOptions *options ); @@ -884,7 +886,7 @@ public: private: - bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels, + bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels, unsigned int firstChannel, unsigned int sampleRate, RtAudioFormat format, unsigned int *bufferSize, RtAudio::StreamOptions *options ); @@ -921,7 +923,7 @@ public: private: - bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels, + bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels, unsigned int firstChannel, unsigned int sampleRate, RtAudioFormat format, unsigned int *bufferSize, RtAudio::StreamOptions *options ); @@ -959,7 +961,7 @@ public: std::vector devices_; void saveDeviceInfo( void ); bool coInitialized_; - bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels, + bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels, unsigned int firstChannel, unsigned int sampleRate, RtAudioFormat format, unsigned int *bufferSize, RtAudio::StreamOptions *options ); @@ -998,7 +1000,7 @@ public: bool buffersRolling; long duplexPrerollBytes; std::vector dsDevices; - bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels, + bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels, unsigned int firstChannel, unsigned int sampleRate, RtAudioFormat format, unsigned int *bufferSize, RtAudio::StreamOptions *options ); @@ -1069,7 +1071,7 @@ public: std::vector devices_; void saveDeviceInfo( void ); - bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels, + bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels, unsigned int firstChannel, unsigned int sampleRate, RtAudioFormat format, unsigned int *bufferSize, RtAudio::StreamOptions *options ); @@ -1133,7 +1135,7 @@ public: private: - bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels, + bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels, unsigned int firstChannel, unsigned int sampleRate, RtAudioFormat format, unsigned int *bufferSize, RtAudio::StreamOptions *options ); @@ -1158,7 +1160,7 @@ public: private: - bool probeDeviceOpen( unsigned int /*device*/, StreamMode /*mode*/, unsigned int /*channels*/, + bool probeDeviceOpen( unsigned int /*device*/, StreamMode /*mode*/, unsigned int /*channels*/, unsigned int /*firstChannel*/, unsigned int /*sampleRate*/, RtAudioFormat /*format*/, unsigned int * /*bufferSize*/, RtAudio::StreamOptions * /*options*/ ) { return false; } diff --git a/source/native-plugins/midi-base.hpp b/source/native-plugins/midi-base.hpp index 165601252..444189cce 100644 --- a/source/native-plugins/midi-base.hpp +++ b/source/native-plugins/midi-base.hpp @@ -302,7 +302,7 @@ public: const RawMidiEvent* const rawMidiEvent(it.getValue(nullptr)); CARLA_SAFE_ASSERT_CONTINUE(rawMidiEvent != nullptr); - wrtn = std::snprintf(dataWrtn, maxTimeSize+4, P_INT64 ":%i:", rawMidiEvent->time, rawMidiEvent->size); + wrtn = std::snprintf(dataWrtn, maxTimeSize+6, P_UINT64 ":%u:", rawMidiEvent->time, rawMidiEvent->size); CARLA_SAFE_ASSERT_BREAK(wrtn > 0); dataWrtn += wrtn; diff --git a/source/native-plugins/midi-pattern.cpp b/source/native-plugins/midi-pattern.cpp index 2731ac2bd..d5a3677a6 100644 --- a/source/native-plugins/midi-pattern.cpp +++ b/source/native-plugins/midi-pattern.cpp @@ -312,7 +312,7 @@ protected: { const CarlaScopedLocale csl; - std::snprintf(strBuf, 0xff, "%f\n", beatsPerMinute); + std::snprintf(strBuf, 0xff, "%.12g\n", beatsPerMinute); } CARLA_SAFE_ASSERT_RETURN(writeMessage(strBuf),); diff --git a/source/plugin/carla-lv2-ui.cpp b/source/plugin/carla-lv2-ui.cpp index d7e3c52c2..f3d9dc29a 100644 --- a/source/plugin/carla-lv2-ui.cpp +++ b/source/plugin/carla-lv2-ui.cpp @@ -139,7 +139,7 @@ public: { const CarlaScopedLocale csl; - std::snprintf(msg, 127, "control %u %f", portIndex, static_cast(*valuePtr)); + std::snprintf(msg, 127, "control %u %.12g", portIndex, static_cast(*valuePtr)); } msg[127] = '\0'; diff --git a/source/utils/CarlaPipeUtils.cpp b/source/utils/CarlaPipeUtils.cpp index 5334100d3..a9a1d24ed 100644 --- a/source/utils/CarlaPipeUtils.cpp +++ b/source/utils/CarlaPipeUtils.cpp @@ -984,7 +984,7 @@ void CarlaPipeCommon::writeControlMessage(const uint32_t index, const float valu { const CarlaScopedLocale csl; - std::snprintf(tmpBuf, 0xff, "%f\n", static_cast(value)); + std::snprintf(tmpBuf, 0xff, "%.12g\n", static_cast(value)); } if (! _writeMsgBuffer(tmpBuf, std::strlen(tmpBuf))) diff --git a/source/utils/CarlaString.hpp b/source/utils/CarlaString.hpp index 16bb14ec4..b39d28d68 100644 --- a/source/utils/CarlaString.hpp +++ b/source/utils/CarlaString.hpp @@ -179,7 +179,7 @@ public: { const CarlaScopedLocale csl; - std::snprintf(strBuf, 0xff, "%f", static_cast(value)); + std::snprintf(strBuf, 0xff, "%.12g", static_cast(value)); } strBuf[0xff] = '\0'; @@ -199,7 +199,7 @@ public: { const CarlaScopedLocale csl; - std::snprintf(strBuf, 0xff, "%f", value); + std::snprintf(strBuf, 0xff, "%.24g", value); } strBuf[0xff] = '\0';