From 9516ec302a99e132361157e17d3129f6ec9239d6 Mon Sep 17 00:00:00 2001 From: Dominykas Date: Wed, 26 Jun 2024 10:20:01 +0300 Subject: [PATCH 1/2] Add warning attributes to formatting functions --- GUI/chips/LMS7002M/lms7002_mainPanel.cpp | 2 +- GUI/oglGraph/OpenGLGraph.cpp | 3 +- GUI/oglGraph/OpenGLGraph.h | 3 +- embedded/lms7002m/privates.c | 3 +- embedded/lms7002m/privates.h | 6 ++-- plugins/amarisoft-plugin/trx_limesuite.cpp | 4 +-- src/API/LMS_APIWrapper.cpp | 4 +-- src/API/LimePlugin.cpp | 35 ++++++++++--------- src/CommonFunctions.h | 2 +- src/comms/PCIe/linux-kernel-module/litepcie.c | 2 +- src/comms/USB/USBGeneric.cpp | 2 +- src/examples/dualRXTX.cpp | 2 +- src/gnuPlotPipe.h | 7 ++-- src/include/limesuiteng/Logger.h | 16 ++++----- src/logger/LoggerCString.cpp | 8 ++--- src/protocols/TRXLooper.cpp | 2 +- src/threadHelper/threadHelper.cpp | 4 +-- 17 files changed, 58 insertions(+), 47 deletions(-) diff --git a/GUI/chips/LMS7002M/lms7002_mainPanel.cpp b/GUI/chips/LMS7002M/lms7002_mainPanel.cpp index ab099c17..470df789 100644 --- a/GUI/chips/LMS7002M/lms7002_mainPanel.cpp +++ b/GUI/chips/LMS7002M/lms7002_mainPanel.cpp @@ -245,7 +245,7 @@ void lms7002_mainPanel::UpdateVisiblePanel() currentTab->second->UpdateGUI(); t2 = wxGetUTCTimeMillis(); #ifndef NDEBUG - lime::debug("Visible GUI update time: "s + (t2 - t1).ToString()); + lime::debug("Visible GUI update time: %li", (t2 - t1).ToLong()); #endif } diff --git a/GUI/oglGraph/OpenGLGraph.cpp b/GUI/oglGraph/OpenGLGraph.cpp index 18044f85..6a62b873 100644 --- a/GUI/oglGraph/OpenGLGraph.cpp +++ b/GUI/oglGraph/OpenGLGraph.cpp @@ -455,9 +455,10 @@ void OpenGLGraph::DrawStaticElements() 0, fheight, 0, + "%s", settings.titleXaxis.c_str()); m_font->getTextSize(settings.titleYaxis.c_str(), tw, th, fheight); - glRenderText(settings.marginLeft + 1, settings.windowHeight - th - 1, 0, fheight, 0, settings.titleYaxis.c_str()); + glRenderText(settings.marginLeft + 1, settings.windowHeight - th - 1, 0, fheight, 0, "%s", settings.titleYaxis.c_str()); double pixelXvalue = 0; double pixelYvalue = 0; diff --git a/GUI/oglGraph/OpenGLGraph.h b/GUI/oglGraph/OpenGLGraph.h index 0e2146b8..0f70121b 100644 --- a/GUI/oglGraph/OpenGLGraph.h +++ b/GUI/oglGraph/OpenGLGraph.h @@ -411,7 +411,8 @@ class OpenGLGraph : public wxGLCanvas void switchToWindowView(); void switchToDataView(); - GLvoid glRenderText(float posx, float posy, float angle, float scale, unsigned int rgba, const char* fmt, ...); + GLvoid glRenderText + [[gnu::format(printf, 7, 8)]] (float posx, float posy, float angle, float scale, unsigned int rgba, const char* fmt, ...); int TextWidthInPixels(const char* str); int NumberWidthInPixels(float num, unsigned int prec = 0); int LineHeight(); diff --git a/embedded/lms7002m/privates.c b/embedded/lms7002m/privates.c index 8460c24a..bd83d583 100644 --- a/embedded/lms7002m/privates.c +++ b/embedded/lms7002m/privates.c @@ -29,7 +29,8 @@ void lms7002m_log(lms7002m_context* context, lime_LogLevel level, const char* fo context->hooks.log(level, buff, context->hooks.log_userData); } -static void lms7002m_log_va(lms7002m_context* context, lime_LogLevel level, const char* format, va_list args) +static void __attribute__((format(printf, 3, 0))) +lms7002m_log_va(lms7002m_context* context, lime_LogLevel level, const char* format, va_list args) { if (context->hooks.log == NULL) return; diff --git a/embedded/lms7002m/privates.h b/embedded/lms7002m/privates.h index 6b3458bd..0231282f 100644 --- a/embedded/lms7002m/privates.h +++ b/embedded/lms7002m/privates.h @@ -16,8 +16,10 @@ struct lms7002m_context; lms7002m_log(context, lime_LogLevel_Debug, format, __VA_ARGS__); \ } while (0) -void lms7002m_log(struct lms7002m_context* context, lime_LogLevel level, const char* format, ...); -lime_Result lms7002m_report_error(struct lms7002m_context* context, lime_Result result, const char* format, ...); +void __attribute__((format(printf, 3, 4))) +lms7002m_log(struct lms7002m_context* context, lime_LogLevel level, const char* format, ...); +lime_Result __attribute__((format(printf, 3, 4))) +lms7002m_report_error(struct lms7002m_context* context, lime_Result result, const char* format, ...); void lms7002m_sleep(long timeInMicroseconds); void lms7002m_spi_write(struct lms7002m_context* self, uint16_t address, uint16_t value); diff --git a/plugins/amarisoft-plugin/trx_limesuite.cpp b/plugins/amarisoft-plugin/trx_limesuite.cpp index 92ddc57d..deff0393 100644 --- a/plugins/amarisoft-plugin/trx_limesuite.cpp +++ b/plugins/amarisoft-plugin/trx_limesuite.cpp @@ -54,7 +54,7 @@ class AmarisoftParamProvider : public LimeSettingsProvider }; static lime::LogLevel logVerbosity = lime::LogLevel::Debug; -static void Log(LogLevel lvl, const char* format, ...) +static void Log [[gnu::format(printf, 2, 3)]] (LogLevel lvl, const char* format, ...) { if (lvl > logVerbosity) return; @@ -235,7 +235,7 @@ static int trx_lms7002m_get_sample_rate(TRXState* s1, TRXFraction* psample_rate, if (rate < bandwidth) { - Log(LogLevel::Error, "Port[%i] Manually specified sample rate %i is less than LTE bandwidth %i", p, rate, bandwidth); + Log(LogLevel::Error, "Port[%i] Manually specified sample rate %f is less than LTE bandwidth %i", p, rate, bandwidth); return -1; } Log(LogLevel::Info, "Port[%i] Manually specified sample rate: %f MSps", p, rate / 1e6); diff --git a/src/API/LMS_APIWrapper.cpp b/src/API/LMS_APIWrapper.cpp index f791faf4..2f98ad5d 100644 --- a/src/API/LMS_APIWrapper.cpp +++ b/src/API/LMS_APIWrapper.cpp @@ -670,7 +670,7 @@ API_EXPORT int CALL_CONV LMS_Calibrate(lms_device_t* device, bool dir_tx, size_t apiDevice->device->Calibrate(apiDevice->moduleIndex, direction, chan, bw); } catch (...) { - lime::error("Failed to calibrate %s channel %i.", ToString(direction).c_str(), chan); + lime::error("Failed to calibrate %s channel %li.", ToString(direction).c_str(), chan); return -1; } @@ -732,7 +732,7 @@ API_EXPORT int CALL_CONV LMS_SetTestSignal( apiDevice->device->SetTestSignal(apiDevice->moduleIndex, direction, chan, enumToTestStruct(sig), dc_i, dc_q); } catch (...) { - lime::error("Failed to set %s channel %i test signal.", ToString(direction).c_str(), chan); + lime::error("Failed to set %s channel %li test signal.", ToString(direction).c_str(), chan); } return 0; diff --git a/src/API/LimePlugin.cpp b/src/API/LimePlugin.cpp index 97a7f0fc..53292935 100644 --- a/src/API/LimePlugin.cpp +++ b/src/API/LimePlugin.cpp @@ -78,7 +78,8 @@ LimePluginContext::LimePluginContext() enum CalibrateFlag { None = 0, DCIQ = 1, Filter = 2 }; -template static bool GetSetting(LimeSettingsProvider* settings, T* pval, const char* prop_name_format, ...) +template +static bool GetSetting [[gnu::format(printf, 3, 4)]] (LimeSettingsProvider* settings, T* pval, const char* prop_name_format, ...) { char name[256]; va_list args; @@ -93,7 +94,8 @@ template static bool GetSetting(LimeSettingsProvider* settings, T* pval return true; } -template<> bool GetSetting(LimeSettingsProvider* settings, std::string* pval, const char* prop_name_format, ...) +template<> +bool GetSetting [[gnu::format(printf, 3, 4)]] (LimeSettingsProvider* settings, std::string* pval, const char* prop_name_format, ...) { char name[256]; va_list args; @@ -104,7 +106,8 @@ template<> bool GetSetting(LimeSettingsProvider* settings, std::string* pval, co return settings->GetString(*pval, name); } -template static bool GetParam(LimePluginContext* context, T& pval, const char* prop_name_format, ...) +template +static bool GetParam [[gnu::format(printf, 3, 4)]] (LimePluginContext* context, T& pval, const char* prop_name_format, ...) { char name[256]; va_list args; @@ -121,7 +124,7 @@ template static bool GetParam(LimePluginContext* context, T& pval, cons static lime::LogLevel logVerbosity = lime::LogLevel::Debug; -static void Log(LogLevel lvl, const char* format, ...) +static void Log [[gnu::format(printf, 2, 3)]] (LogLevel lvl, const char* format, ...) { if (lvl > logVerbosity) return; @@ -166,7 +169,7 @@ bool OnStreamStatusChange(bool isTx, const StreamStats* s, void* userData) << " MB/s"sv << "\nTx| Late: "sv << status.tx.loss << " underrun: "sv << status.tx.underrun << " rate: "sv << status.tx.dataRate_Bps / 1e6 << " MB/s"sv; - Log(LogLevel::Warning, ss.str().c_str()); + Log(LogLevel::Warning, "%s", ss.str().c_str()); lastStreamUpdate = now; } return false; @@ -415,7 +418,7 @@ static OpStatus LoadDevicesConfigurationFile(LimePluginContext* context) const auto& desc = node.device->GetDescriptor(); if (node.chipIndex >= desc.rfSOC.size()) { - Log(LogLevel::Error, "Invalid chipIndex (%i). dev%i has only %i chips.", node.chipIndex, i, desc.rfSOC.size()); + Log(LogLevel::Error, "Invalid chipIndex (%i). dev%li has only %li chips.", node.chipIndex, i, desc.rfSOC.size()); return OpStatus::OutOfRange; } @@ -432,12 +435,12 @@ static OpStatus LoadDevicesConfigurationFile(LimePluginContext* context) if (chip->LoadConfig(configFilepath, false) != OpStatus::Success) { - Log(LogLevel::Error, "dev%s chip%i Error loading file: %s", i, node.chipIndex, configFilepath.c_str()); + Log(LogLevel::Error, "dev%li chip%i Error loading file: %s", i, node.chipIndex, configFilepath.c_str()); return OpStatus::Error; } node.config.skipDefaults = true; - Log(LogLevel::Info, "dev%i chip%i loaded with: %s", i, node.chipIndex, configFilepath.c_str()); + Log(LogLevel::Info, "dev%li chip%i loaded with: %s", i, node.chipIndex, configFilepath.c_str()); } return OpStatus::Success; } @@ -529,7 +532,7 @@ static void GatherDeviceTreeNodeSettings(LimePluginContext* context, LimeSetting DevNode& dev = context->rfdev.at(i); char devPrefix[16]; std::snprintf(devPrefix, sizeof(devPrefix), "dev%i", i); - GetSetting(settings, &dev.handleString, devPrefix); + GetSetting(settings, &dev.handleString, "%s", devPrefix); GetSetting(settings, &dev.chipIndex, "%s_chip_index", devPrefix); GatherConfigSettings(&dev.configInputs, settings, devPrefix); @@ -546,7 +549,7 @@ static OpStatus GatherPortSettings(LimePluginContext* context, LimeSettingsProvi char portPrefix[16]; std::snprintf(portPrefix, sizeof(portPrefix), "port%i", i); GatherConfigSettings(&port.configInputs, settings, portPrefix); - if (GetSetting(settings, &port.deviceNames, portPrefix)) + if (GetSetting(settings, &port.deviceNames, "%s", portPrefix)) { ++specifiedPortsCount; OpStatus status = AssignDevicesToPorts(context); @@ -791,7 +794,7 @@ static void TransferRuntimeParametersToConfig( params.freq[i] / 1.0e6, trxConfig.centerFrequency / 1.0e6, (trxConfig.centerFrequency - params.freq[i]) / 1.0e6); - Log(LogLevel::Info, loFreqStr); + Log(LogLevel::Info, "%s", loFreqStr); } if (trxConfig.gfir.bandwidth == 0) // update only if not set by settings file @@ -804,7 +807,7 @@ static void TransferRuntimeParametersToConfig( const auto& paths = desc.pathNames.at(isTx ? TRXDir::Tx : TRXDir::Rx); Log(LogLevel::Verbose, - "%s channel%i: dev%i chip%i ch%i , LO: %.3f MHz SR: %.3f MHz BW: %.3f MHz | path: %i('%s')", + "%s channel%li: dev%i chip%i ch%i , LO: %.3f MHz SR: %.3f MHz BW: %.3f MHz | path: %i('%s')", isTx ? "Tx" : "Rx", i, channelMap[i].parent->devIndex, @@ -862,7 +865,7 @@ OpStatus ConfigureStreaming(LimePluginContext* context, const LimeRuntimeParamet continue; Log(LogLevel::Debug, - "Port[%i] Stream samples format: %s , link: %s %s", + "Port[%li] Stream samples format: %s , link: %s %s", p, stream.format == DataFormat::F32 ? "F32" : "I16", stream.linkFormat == DataFormat::I12 ? "I12" : "I16", @@ -871,7 +874,7 @@ OpStatus ConfigureStreaming(LimePluginContext* context, const LimeRuntimeParamet port.composite = new StreamComposite(aggregates); if (port.composite->StreamSetup(stream) != OpStatus::Success) { - Log(LogLevel::Error, "Port%i stream setup failed.", p); + Log(LogLevel::Error, "Port%li stream setup failed.", p); return OpStatus::Error; } } @@ -900,12 +903,12 @@ int LimePlugin_Setup(LimePluginContext* context, const LimeRuntimeParameters* pa continue; else if (node.device != nullptr && !node.assignedToPort) { - Log(LogLevel::Warning, "dev%i is not assigned to any port.", i); + Log(LogLevel::Warning, "dev%li is not assigned to any port.", i); continue; } try { - Log(LogLevel::Debug, "dev%i configure.", i); + Log(LogLevel::Debug, "dev%li configure.", i); OpStatus status = node.device->Configure(node.config, node.chipIndex); if (status != OpStatus::Success) return -1; diff --git a/src/CommonFunctions.h b/src/CommonFunctions.h index 3210fc55..fcfa8cf8 100644 --- a/src/CommonFunctions.h +++ b/src/CommonFunctions.h @@ -8,7 +8,7 @@ namespace lime { -const std::string strFormat(const char* format, ...); +const std::string strFormat [[gnu::format(printf, 1, 2)]] (const char* format, ...); template std::string intToHex(T i) { diff --git a/src/comms/PCIe/linux-kernel-module/litepcie.c b/src/comms/PCIe/linux-kernel-module/litepcie.c index 9cdb6ccc..d4d0f63a 100644 --- a/src/comms/PCIe/linux-kernel-module/litepcie.c +++ b/src/comms/PCIe/linux-kernel-module/litepcie.c @@ -1344,7 +1344,7 @@ static void litepcie_free_chdev(struct litepcie_device *s) } /* from stackoverflow */ -void sfind(char *string, char *format, ...) +void __attribute__((format(scanf, 2, 3))) sfind(char *string, char *format, ...) { va_list arglist; diff --git a/src/comms/USB/USBGeneric.cpp b/src/comms/USB/USBGeneric.cpp index bf44510a..0a5a11c3 100644 --- a/src/comms/USB/USBGeneric.cpp +++ b/src/comms/USB/USBGeneric.cpp @@ -307,7 +307,7 @@ int32_t USBGeneric::BulkTransfer(uint8_t endPointAddr, uint8_t* data, size_t len int status = libusb_bulk_transfer(dev_handle, endPointAddr, data, length, &actualTransferred, timeout_ms); if (status != 0) { - lime::error("USBGeneric::BulkTransfer(0x%02X) : %s, transferred: %i, expected: %i", + lime::error("USBGeneric::BulkTransfer(0x%02X) : %s, transferred: %i, expected: %lu", endPointAddr, libusb_error_name(status), actualTransferred, diff --git a/src/examples/dualRXTX.cpp b/src/examples/dualRXTX.cpp index 71efe7f7..4d972614 100644 --- a/src/examples/dualRXTX.cpp +++ b/src/examples/dualRXTX.cpp @@ -166,7 +166,7 @@ int main(int argc, char** argv) #ifdef USE_GNU_PLOT gp.write("plot '-' with points title 'ch 0'"); for (std::size_t c = 1; c < stream.channels.at(TRXDir::Rx).size(); ++c) - gp.writef(", '-' with points title 'ch %i'\n", c); + gp.writef(", '-' with points title 'ch %lu'\n", c); for (std::size_t c = 0; c < stream.channels.at(TRXDir::Rx).size(); ++c) { for (uint32_t n = 0; n < samplesInBuffer; ++n) diff --git a/src/gnuPlotPipe.h b/src/gnuPlotPipe.h index 4a417aee..978b9b4f 100644 --- a/src/gnuPlotPipe.h +++ b/src/gnuPlotPipe.h @@ -47,7 +47,7 @@ class GNUPlotPipe /// @brief Writes formatted data into the pipe. /// @param format The format string. /// @param ... The format arguments parameters. - void writef(const char* format, ...) + void writef [[gnu::format(printf, 2, 3)]] (const char* format, ...) { static char temp[512]; va_list argList; @@ -58,7 +58,10 @@ class GNUPlotPipe } /// @brief Flushes the pipe. - void flush() { fflush(pipeHandle); } + void flush() + { + fflush(pipeHandle); + } protected: FILE* pipeHandle; diff --git a/src/include/limesuiteng/Logger.h b/src/include/limesuiteng/Logger.h index c98fa16b..663230e4 100644 --- a/src/include/limesuiteng/Logger.h +++ b/src/include/limesuiteng/Logger.h @@ -43,23 +43,23 @@ LIME_API const char* GetLastErrorMessageCString(void); LIME_API const std::string& GetLastErrorMessage(void); // C-string versions -LIME_API void critical(const char* format, ...); //!< Log a critical error message with formatting +LIME_API void critical [[gnu::format(printf, 1, 2)]] (const char* format, ...); //!< Log a critical error message with formatting LIME_API void critical(const std::string& text); //!< Log a critical error message -LIME_API int error(const char* format, ...); //!< Log an error message with formatting +LIME_API int error [[gnu::format(printf, 1, 2)]] (const char* format, ...); //!< Log an error message with formatting LIME_API int error(const std::string& text); //!< Log an error message -LIME_API void warning(const char* format, ...); //!< Log a warning message with formatting +LIME_API void warning [[gnu::format(printf, 1, 2)]] (const char* format, ...); //!< Log a warning message with formatting LIME_API void warning(const std::string& text); //!< Log a warning message -LIME_API void info(const char* format, ...); //!< Log an information message with formatting +LIME_API void info [[gnu::format(printf, 1, 2)]] (const char* format, ...); //!< Log an information message with formatting LIME_API void info(const std::string& text); //!< Log an information message -LIME_API void debug(const char* format, ...); //!< Log a debug message with formatting +LIME_API void debug [[gnu::format(printf, 1, 2)]] (const char* format, ...); //!< Log a debug message with formatting LIME_API void debug(const std::string& text); //!< Log a debug message //! Log a message with formatting and specified logging level -LIME_API void log(const LogLevel level, const char* format, ...); +LIME_API void log [[gnu::format(printf, 2, 3)]] (const LogLevel level, const char* format, ...); //! Log a message with specified logging level LIME_API void log(const LogLevel level, const std::string& text); @@ -77,10 +77,10 @@ LIME_API OpStatus ReportError(const OpStatus errnum); * \param format a format string followed by args * \return passthrough errnum */ -LIME_API OpStatus ReportError(const OpStatus errnum, const char* format, ...); +LIME_API OpStatus ReportError [[gnu::format(printf, 2, 3)]] (const OpStatus errnum, const char* format, ...); LIME_API OpStatus ReportError(const OpStatus errnum, const std::string& text); -LIME_API int ReportError(const int errnum, const char* format, ...); +LIME_API int ReportError [[gnu::format(printf, 2, 3)]] (const int errnum, const char* format, ...); LIME_API int ReportError(const int errnum, const std::string& text); } // namespace lime diff --git a/src/logger/LoggerCString.cpp b/src/logger/LoggerCString.cpp index bab3c335..f48307bd 100644 --- a/src/logger/LoggerCString.cpp +++ b/src/logger/LoggerCString.cpp @@ -28,7 +28,7 @@ const char* GetLastErrorMessageCString(void) return Logger::_reportedErrorMessage.c_str(); } -void log(const LogLevel level, const char* format, va_list argList) +void log [[gnu::format(printf, 2, 0)]] (const LogLevel level, const char* format, va_list argList) { char buff[4096]; int ret = std::vsnprintf(buff, sizeof(buff), format, argList); @@ -87,7 +87,7 @@ void log(const LogLevel level, const char* format, ...) static constexpr std::size_t MAX_MSG_LEN = 1024; thread_local char _reportedErrorMessageCStringBuffer[MAX_MSG_LEN]; -template inline T ReportErrorTemplate(const T errnum, const char* format, va_list argList) +template inline T ReportErrorTemplate [[gnu::format(printf, 2, 0)]] (const T errnum, const char* format, va_list argList) { Logger::_reportedErrorCode = static_cast(errnum); @@ -101,12 +101,12 @@ template inline T ReportErrorTemplate(const T errnum, const char* forma return errnum; } -int ReportError(const int errnum, const char* format, va_list argList) +int ReportError [[gnu::format(printf, 2, 0)]] (const int errnum, const char* format, va_list argList) { return ReportErrorTemplate(errnum, format, argList); } -OpStatus ReportError(const OpStatus errnum, const char* format, va_list argList) +OpStatus ReportError [[gnu::format(printf, 2, 0)]] (const OpStatus errnum, const char* format, va_list argList) { return ReportErrorTemplate(errnum, format, argList); } diff --git a/src/protocols/TRXLooper.cpp b/src/protocols/TRXLooper.cpp index 1014136e..4c9d1e1b 100644 --- a/src/protocols/TRXLooper.cpp +++ b/src/protocols/TRXLooper.cpp @@ -482,7 +482,7 @@ void TRXLooper::ReceivePacketsLoop() mRx.memPool->Allocate(outputPktSize), samplesInPkt * mRxArgs.packetsToBatch, outputSampleSize); if (outputPkt == nullptr) { - lime::warning("Rx%i: packets fifo full."); + lime::warning("Rx%i: packets fifo full.", chipId); continue; } } diff --git a/src/threadHelper/threadHelper.cpp b/src/threadHelper/threadHelper.cpp index bea7af54..3d396d74 100644 --- a/src/threadHelper/threadHelper.cpp +++ b/src/threadHelper/threadHelper.cpp @@ -54,7 +54,7 @@ int lime::SetOSThreadPriority(ThreadPriority priority, ThreadPolicy policy, std: if (int ret = pthread_setschedparam(thread->native_handle(), sched_policy, &sch)) { lime::debug("SetOSThreadPriority: Failed to set priority(%d), schec_prio(%d), policy(%d), ret(%d)", - priority, + static_cast(priority), sched_policy, ret, sch.sched_priority); @@ -99,7 +99,7 @@ int lime::SetOSCurrentThreadPriority(ThreadPriority priority, ThreadPolicy polic if (int ret = pthread_setschedparam(pthread_self(), sched_policy, &sch) != 0) { lime::debug("SetOSCurrentThreadPriority: Failed to set priority(%d), schec_prio(%d), policy(%d), ret(%d)", - priority, + static_cast(priority), sched_policy, ret, sch.sched_priority); From bf6f11b7228f970454666b8d3503eefbc49c5861 Mon Sep 17 00:00:00 2001 From: Dominykas Date: Wed, 26 Jun 2024 10:46:39 +0300 Subject: [PATCH 2/2] Fix Windows compilation --- embedded/lms7002m/privates.c | 4 ++-- embedded/lms7002m/privates.h | 13 +++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/embedded/lms7002m/privates.c b/embedded/lms7002m/privates.c index bd83d583..2f7d6ecd 100644 --- a/embedded/lms7002m/privates.c +++ b/embedded/lms7002m/privates.c @@ -29,8 +29,8 @@ void lms7002m_log(lms7002m_context* context, lime_LogLevel level, const char* fo context->hooks.log(level, buff, context->hooks.log_userData); } -static void __attribute__((format(printf, 3, 0))) -lms7002m_log_va(lms7002m_context* context, lime_LogLevel level, const char* format, va_list args) +static void FORMAT_ATTR(printf, 3, 0) + lms7002m_log_va(lms7002m_context* context, lime_LogLevel level, const char* format, va_list args) { if (context->hooks.log == NULL) return; diff --git a/embedded/lms7002m/privates.h b/embedded/lms7002m/privates.h index 0231282f..ea20b6e9 100644 --- a/embedded/lms7002m/privates.h +++ b/embedded/lms7002m/privates.h @@ -16,10 +16,15 @@ struct lms7002m_context; lms7002m_log(context, lime_LogLevel_Debug, format, __VA_ARGS__); \ } while (0) -void __attribute__((format(printf, 3, 4))) -lms7002m_log(struct lms7002m_context* context, lime_LogLevel level, const char* format, ...); -lime_Result __attribute__((format(printf, 3, 4))) -lms7002m_report_error(struct lms7002m_context* context, lime_Result result, const char* format, ...); +#ifdef __unix__ + #define FORMAT_ATTR(type, fmt_str, fmt_param) __attribute__((format(type, fmt_str, fmt_param))) +#else + #define FORMAT_ATTR(type, fmt_str, fmt_param) +#endif + +void FORMAT_ATTR(printf, 3, 4) lms7002m_log(struct lms7002m_context* context, lime_LogLevel level, const char* format, ...); +lime_Result FORMAT_ATTR(printf, 3, 4) + lms7002m_report_error(struct lms7002m_context* context, lime_Result result, const char* format, ...); void lms7002m_sleep(long timeInMicroseconds); void lms7002m_spi_write(struct lms7002m_context* self, uint16_t address, uint16_t value);