From 8a08d5797c74871a0435fd513533c246b9a8d9c6 Mon Sep 17 00:00:00 2001 From: Arkadiusz Bokowy Date: Tue, 15 Oct 2024 19:28:13 +0200 Subject: [PATCH] Use standard std::min std::max functions (#36065) * Use standard std::min std::max functions * Restyled by clang-format * Convert some more max calls * More updates * Another fix * Add missing include --------- Co-authored-by: Restyled.io --- examples/chip-tool/commands/common/Commands.h | 2 +- .../src/EnergyEvseDelegateImpl.cpp | 8 +++---- .../fabric-admin/commands/common/Commands.h | 2 +- .../OTAProviderExample.cpp | 2 +- .../platform/nrfconnect/util/PWMDevice.cpp | 4 +++- .../silabs/SiWx917/SiWx917/sl_wifi_if.cpp | 8 ++----- .../platform/silabs/efr32/rs911x/rsi_if.cpp | 2 +- .../platform/silabs/efr32/wf200/host_if.cpp | 2 +- examples/platform/silabs/uart.cpp | 6 +---- .../platform/silabs/wifi/wfx_rsi_host.cpp | 2 +- .../DefaultAttributePersistenceProvider.cpp | 2 +- .../DeferredAttributePersistenceProvider.cpp | 2 +- src/app/InteractionModelEngine.cpp | 2 +- src/app/MessageDef/StatusIB.cpp | 4 ++-- src/app/OperationalSessionSetup.cpp | 2 +- .../color-control-server.cpp | 24 +++++++++---------- .../network-commissioning.cpp | 2 +- .../DefaultOTARequestorDriver.cpp | 6 ++--- .../clusters/scenes-server/SceneTableImpl.cpp | 4 ++-- .../thread-network-diagnostics-provider.cpp | 2 +- src/ble/BLEEndPoint.cpp | 6 ++--- src/ble/BtpEngine.cpp | 2 +- src/crypto/CHIPCryptoPALPSA.cpp | 4 ++-- src/inet/IPAddress-StringFuncts.cpp | 5 ++-- src/inet/tests/TestInetLayerCommon.cpp | 2 +- src/inet/tests/inet-layer-test-tool.cpp | 2 +- src/lib/core/OTAImageHeader.cpp | 2 +- src/lib/core/tests/TestOTAImageHeader.cpp | 2 +- src/lib/dnssd/ServiceNaming.cpp | 2 +- src/lib/support/BufferReader.h | 2 +- src/lib/support/CodeUtils.h | 24 ------------------- src/lib/support/SafeString.h | 6 +++-- src/lib/support/ZclString.cpp | 2 +- src/platform/ASR/ASRUtils.cpp | 4 ++-- src/platform/Darwin/DnssdContexts.cpp | 2 +- .../ESP32/DiagnosticDataProviderImpl.cpp | 2 +- src/platform/ESP32/ESP32Utils.cpp | 10 ++++---- .../PSOC6/ConnectivityManagerImpl.cpp | 4 ++-- src/platform/Infineon/PSOC6/PSOC6Utils.cpp | 14 +++++------ src/platform/android/AndroidConfig.cpp | 2 +- src/platform/mt793x/DnssdContexts.cpp | 2 +- .../nxp/common/ota/OTATlvProcessor.cpp | 4 ++-- src/platform/silabs/MigrationManager.cpp | 2 +- .../silabs/multi-ota/OTATlvProcessor.cpp | 4 ++-- src/platform/tests/TestKeyValueStoreMgr.cpp | 2 +- src/protocols/bdx/BdxTransferSession.cpp | 4 ++-- src/system/SystemPacketBuffer.h | 2 +- src/transport/raw/MessageHeader.h | 2 +- 48 files changed, 91 insertions(+), 118 deletions(-) diff --git a/examples/chip-tool/commands/common/Commands.h b/examples/chip-tool/commands/common/Commands.h index e6a392cbee..e514e34321 100644 --- a/examples/chip-tool/commands/common/Commands.h +++ b/examples/chip-tool/commands/common/Commands.h @@ -29,7 +29,7 @@ class Commands { public: - using CommandsVector = ::std::vector>; + using CommandsVector = std::vector>; void RegisterCluster(const char * clusterName, commands_list commandsList) { diff --git a/examples/energy-management-app/energy-management-common/energy-evse/src/EnergyEvseDelegateImpl.cpp b/examples/energy-management-app/energy-management-common/energy-evse/src/EnergyEvseDelegateImpl.cpp index 0294a0349e..0305a58381 100644 --- a/examples/energy-management-app/energy-management-common/energy-evse/src/EnergyEvseDelegateImpl.cpp +++ b/examples/energy-management-app/energy-management-common/energy-evse/src/EnergyEvseDelegateImpl.cpp @@ -934,10 +934,10 @@ Status EnergyEvseDelegate::ComputeMaxChargeCurrentLimit() oldValue = mActualChargingCurrentLimit; mActualChargingCurrentLimit = mMaxHardwareCurrentLimit; - mActualChargingCurrentLimit = min(mActualChargingCurrentLimit, mCircuitCapacity); - mActualChargingCurrentLimit = min(mActualChargingCurrentLimit, mCableAssemblyCurrentLimit); - mActualChargingCurrentLimit = min(mActualChargingCurrentLimit, mMaximumChargingCurrentLimitFromCommand); - mActualChargingCurrentLimit = min(mActualChargingCurrentLimit, mUserMaximumChargeCurrent); + mActualChargingCurrentLimit = std::min(mActualChargingCurrentLimit, mCircuitCapacity); + mActualChargingCurrentLimit = std::min(mActualChargingCurrentLimit, mCableAssemblyCurrentLimit); + mActualChargingCurrentLimit = std::min(mActualChargingCurrentLimit, mMaximumChargingCurrentLimitFromCommand); + mActualChargingCurrentLimit = std::min(mActualChargingCurrentLimit, mUserMaximumChargeCurrent); /* Set the actual max charging current attribute */ mMaximumChargeCurrent = mActualChargingCurrentLimit; diff --git a/examples/fabric-admin/commands/common/Commands.h b/examples/fabric-admin/commands/common/Commands.h index f071ac08c4..693c33e0ca 100644 --- a/examples/fabric-admin/commands/common/Commands.h +++ b/examples/fabric-admin/commands/common/Commands.h @@ -29,7 +29,7 @@ class Commands { public: - using CommandsVector = ::std::vector>; + using CommandsVector = std::vector>; void RegisterCluster(const char * clusterName, commands_list commandsList) { diff --git a/examples/ota-provider-app/ota-provider-common/OTAProviderExample.cpp b/examples/ota-provider-app/ota-provider-common/OTAProviderExample.cpp index 381d3b43f7..d93a61dfbd 100644 --- a/examples/ota-provider-app/ota-provider-common/OTAProviderExample.cpp +++ b/examples/ota-provider-app/ota-provider-common/OTAProviderExample.cpp @@ -61,7 +61,7 @@ constexpr uint32_t kBdxServerPollIntervalMillis = 50; void GetUpdateTokenString(const chip::ByteSpan & token, char * buf, size_t bufSize) { const uint8_t * tokenData = static_cast(token.data()); - size_t minLength = chip::min(token.size(), bufSize); + size_t minLength = std::min(token.size(), bufSize); for (size_t i = 0; i < (minLength / 2) - 1; ++i) { snprintf(&buf[i * 2], bufSize, "%02X", tokenData[i]); diff --git a/examples/platform/nrfconnect/util/PWMDevice.cpp b/examples/platform/nrfconnect/util/PWMDevice.cpp index d0a77ab63f..67836224ce 100644 --- a/examples/platform/nrfconnect/util/PWMDevice.cpp +++ b/examples/platform/nrfconnect/util/PWMDevice.cpp @@ -18,6 +18,8 @@ #include "PWMDevice.h" +#include + #include "AppConfig.h" #include @@ -129,7 +131,7 @@ void PWMDevice::SuppressOutput() void PWMDevice::ApplyLevel() { const uint8_t maxEffectiveLevel = mMaxLevel - mMinLevel; - const uint8_t effectiveLevel = mState == kState_On ? chip::min(mLevel - mMinLevel, maxEffectiveLevel) : 0; + const uint8_t effectiveLevel = mState == kState_On ? std::min(mLevel - mMinLevel, maxEffectiveLevel) : 0; pwm_set_pulse_dt(mPwmDevice, static_cast(static_cast(mPwmDevice->period) * effectiveLevel / maxEffectiveLevel)); diff --git a/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp b/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp index d283f05162..9dd91a4406 100644 --- a/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp +++ b/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp @@ -94,10 +94,6 @@ bool ps_requirement_added = false; // TODO: Figure out why we actually need this, we are already handling failure and retries somewhere else. #define WIFI_SCAN_TIMEOUT_TICK 10000 -#if !defined(MIN) -#define MIN(A, B) ((A) < (B) ? (A) : (B)) -#endif - WfxRsi_t wfx_rsi; bool hasNotifiedIPV6 = false; @@ -541,12 +537,12 @@ sl_status_t show_scan_results(sl_wifi_scan_result_t * scan_result) memset(&cur_scan_result, 0, sizeof(cur_scan_result)); cur_scan_result.ssid_length = strnlen((char *) scan_result->scan_info[idx].ssid, - chip::min(sizeof(scan_result->scan_info[idx].ssid), WFX_MAX_SSID_LENGTH)); + std::min(sizeof(scan_result->scan_info[idx].ssid), WFX_MAX_SSID_LENGTH)); chip::Platform::CopyString(cur_scan_result.ssid, cur_scan_result.ssid_length, (char *) scan_result->scan_info[idx].ssid); // if user has provided ssid, then check if the current scan result ssid matches the user provided ssid if (wfx_rsi.scan_ssid != NULL && - (strncmp(wfx_rsi.scan_ssid, cur_scan_result.ssid, MIN(strlen(wfx_rsi.scan_ssid), strlen(cur_scan_result.ssid))) == + (strncmp(wfx_rsi.scan_ssid, cur_scan_result.ssid, std::min(strlen(wfx_rsi.scan_ssid), strlen(cur_scan_result.ssid))) == CMP_SUCCESS)) { continue; diff --git a/examples/platform/silabs/efr32/rs911x/rsi_if.cpp b/examples/platform/silabs/efr32/rs911x/rsi_if.cpp index 02500c80f7..4e9c40974c 100644 --- a/examples/platform/silabs/efr32/rs911x/rsi_if.cpp +++ b/examples/platform/silabs/efr32/rs911x/rsi_if.cpp @@ -752,7 +752,7 @@ void ProcessEvent(WfxEvent_t inEvent) // clear structure and calculate size of SSID memset(&ap, 0, sizeof(ap)); ap.ssid_length = - strnlen(reinterpret_cast(scan->ssid), chip::min(sizeof(scan->ssid), WFX_MAX_SSID_LENGTH)); + strnlen(reinterpret_cast(scan->ssid), std::min(sizeof(scan->ssid), WFX_MAX_SSID_LENGTH)); chip::Platform::CopyString(ap.ssid, ap.ssid_length, reinterpret_cast(scan->ssid)); // check if the scanned ssid is the one we are looking for diff --git a/examples/platform/silabs/efr32/wf200/host_if.cpp b/examples/platform/silabs/efr32/wf200/host_if.cpp index 044ecc6e97..516abca22b 100644 --- a/examples/platform/silabs/efr32/wf200/host_if.cpp +++ b/examples/platform/silabs/efr32/wf200/host_if.cpp @@ -736,7 +736,7 @@ int32_t wfx_get_ap_info(wfx_wifi_scan_result_t * ap) { int32_t signal_strength; - ap->ssid_length = strnlen(ap_info.ssid, chip::min(sizeof(ap_info.ssid), WFX_MAX_SSID_LENGTH)); + ap->ssid_length = strnlen(ap_info.ssid, std::min(sizeof(ap_info.ssid), WFX_MAX_SSID_LENGTH)); chip::Platform::CopyString(ap->ssid, ap->ssid_length, ap_info.ssid); memcpy(ap->bssid, ap_info.bssid, sizeof(ap_info.bssid)); ap->security = ap_info.security; diff --git a/examples/platform/silabs/uart.cpp b/examples/platform/silabs/uart.cpp index a43a23fa2c..1af3cb75d9 100644 --- a/examples/platform/silabs/uart.cpp +++ b/examples/platform/silabs/uart.cpp @@ -65,10 +65,6 @@ extern "C" { #include "sl_power_manager.h" #endif -#if !defined(MIN) -#define MIN(A, B) ((A) < (B) ? (A) : (B)) -#endif - #ifdef SL_CATALOG_UARTDRV_EUSART_PRESENT #define HELPER1(x) EUSART##x##_RX_IRQn #else @@ -278,7 +274,7 @@ static uint16_t RetrieveFromFifo(Fifo_t * fifo, uint8_t * pData, uint16_t SizeTo VerifyOrDie(pData != nullptr); VerifyOrDie(SizeToRead <= fifo->MaxSize); - uint16_t ReadSize = MIN(SizeToRead, AvailableDataCount(fifo)); + uint16_t ReadSize = std::min(SizeToRead, AvailableDataCount(fifo)); uint16_t nBytesBeforWrap = (fifo->MaxSize - fifo->Head); if (ReadSize > nBytesBeforWrap) diff --git a/examples/platform/silabs/wifi/wfx_rsi_host.cpp b/examples/platform/silabs/wifi/wfx_rsi_host.cpp index 130d9c90d1..d76bc9c795 100644 --- a/examples/platform/silabs/wifi/wfx_rsi_host.cpp +++ b/examples/platform/silabs/wifi/wfx_rsi_host.cpp @@ -369,7 +369,7 @@ bool wfx_start_scan(char * ssid, void (*callback)(wfx_wifi_scan_result_t *)) wfx_rsi.scan_cb = callback; VerifyOrReturnError(ssid != nullptr, false); - wfx_rsi.scan_ssid_length = strnlen(ssid, chip::min(sizeof(ssid), WFX_MAX_SSID_LENGTH)); + wfx_rsi.scan_ssid_length = strnlen(ssid, std::min(sizeof(ssid), WFX_MAX_SSID_LENGTH)); wfx_rsi.scan_ssid = reinterpret_cast(chip::Platform::MemoryAlloc(wfx_rsi.scan_ssid_length)); VerifyOrReturnError(wfx_rsi.scan_ssid != nullptr, false); chip::Platform::CopyString(wfx_rsi.scan_ssid, wfx_rsi.scan_ssid_length, ssid); diff --git a/src/app/DefaultAttributePersistenceProvider.cpp b/src/app/DefaultAttributePersistenceProvider.cpp index 6e7120999f..40ce521362 100644 --- a/src/app/DefaultAttributePersistenceProvider.cpp +++ b/src/app/DefaultAttributePersistenceProvider.cpp @@ -41,7 +41,7 @@ CHIP_ERROR DefaultAttributePersistenceProvider::InternalReadValue(const StorageK { VerifyOrReturnError(mStorage != nullptr, CHIP_ERROR_INCORRECT_STATE); - uint16_t size = static_cast(min(aValue.size(), static_cast(UINT16_MAX))); + uint16_t size = static_cast(std::min(aValue.size(), static_cast(UINT16_MAX))); ReturnErrorOnFailure(mStorage->SyncGetKeyValue(aKey.KeyName(), aValue.data(), size)); aValue.reduce_size(size); return CHIP_NO_ERROR; diff --git a/src/app/DeferredAttributePersistenceProvider.cpp b/src/app/DeferredAttributePersistenceProvider.cpp index 8265279280..9480fba14e 100644 --- a/src/app/DeferredAttributePersistenceProvider.cpp +++ b/src/app/DeferredAttributePersistenceProvider.cpp @@ -81,7 +81,7 @@ void DeferredAttributePersistenceProvider::FlushAndScheduleNext() } else { - nextFlushTime = chip::min(nextFlushTime, da.GetFlushTime()); + nextFlushTime = std::min(nextFlushTime, da.GetFlushTime()); } } diff --git a/src/app/InteractionModelEngine.cpp b/src/app/InteractionModelEngine.cpp index 5f0e392c26..6f326b5fdb 100644 --- a/src/app/InteractionModelEngine.cpp +++ b/src/app/InteractionModelEngine.cpp @@ -1929,7 +1929,7 @@ uint16_t InteractionModelEngine::GetMinGuaranteedSubscriptionsPerFabric() const return UINT16_MAX; #else return static_cast( - min(GetReadHandlerPoolCapacityForSubscriptions() / GetConfigMaxFabrics(), static_cast(UINT16_MAX))); + std::min(GetReadHandlerPoolCapacityForSubscriptions() / GetConfigMaxFabrics(), static_cast(UINT16_MAX))); #endif } diff --git a/src/app/MessageDef/StatusIB.cpp b/src/app/MessageDef/StatusIB.cpp index 63012cc64f..e1f4d6a74b 100644 --- a/src/app/MessageDef/StatusIB.cpp +++ b/src/app/MessageDef/StatusIB.cpp @@ -168,7 +168,7 @@ bool FormatStatusIBError(char * buf, uint16_t bufSize, CHIP_ERROR err) // formatted string, as long as we account for the possible string formats. constexpr size_t statusNameMaxLength = #define CHIP_IM_STATUS_CODE(name, spec_name, value) \ - max(sizeof(#spec_name), + std::max(sizeof(#spec_name), #include #undef CHIP_IM_STATUS_CODE static_cast(0) @@ -177,7 +177,7 @@ bool FormatStatusIBError(char * buf, uint16_t bufSize, CHIP_ERROR err) #include #undef CHIP_IM_STATUS_CODE ; - constexpr size_t formattedSize = max(sizeof(generalFormat) + statusNameMaxLength, sizeof(clusterFormat)); + constexpr size_t formattedSize = std::max(sizeof(generalFormat) + statusNameMaxLength, sizeof(clusterFormat)); char formattedString[formattedSize]; StatusIB status(err); diff --git a/src/app/OperationalSessionSetup.cpp b/src/app/OperationalSessionSetup.cpp index 3a9c4be619..a0af8fa3d0 100644 --- a/src/app/OperationalSessionSetup.cpp +++ b/src/app/OperationalSessionSetup.cpp @@ -744,7 +744,7 @@ CHIP_ERROR OperationalSessionSetup::ScheduleSessionSetupReattempt(System::Clock: "Our backoff calculation will overflow."); System::Clock::Timeout actualTimerDelay = System::Clock::Seconds16( static_cast(CHIP_DEVICE_CONFIG_AUTOMATIC_CASE_RETRY_INITIAL_DELAY_SECONDS - << min((mAttemptsDone - 1), CHIP_DEVICE_CONFIG_AUTOMATIC_CASE_RETRY_MAX_BACKOFF))); + << std::min((mAttemptsDone - 1), CHIP_DEVICE_CONFIG_AUTOMATIC_CASE_RETRY_MAX_BACKOFF))); const bool responseWasBusy = mRequestedBusyDelay != System::Clock::kZero; if (responseWasBusy) { diff --git a/src/app/clusters/color-control-server/color-control-server.cpp b/src/app/clusters/color-control-server/color-control-server.cpp index 2a85888422..d43590da31 100644 --- a/src/app/clusters/color-control-server/color-control-server.cpp +++ b/src/app/clusters/color-control-server/color-control-server.cpp @@ -1093,7 +1093,7 @@ void ColorControlServer::SetHSVRemainingTime(chip::EndpointId endpoint) { bool hsvTransitionStart = (hueTransitionState->stepsRemaining == hueTransitionState->stepsTotal) || (saturationTransitionState->stepsRemaining == saturationTransitionState->stepsTotal); - SetQuietReportRemainingTime(endpoint, max(hueTransitionState->timeRemaining, saturationTransitionState->timeRemaining), + SetQuietReportRemainingTime(endpoint, std::max(hueTransitionState->timeRemaining, saturationTransitionState->timeRemaining), hsvTransitionStart); } } @@ -1283,7 +1283,7 @@ Status ColorControlServer::moveToSaturation(uint8_t saturation, uint16_t transit // now, kick off the state machine. initSaturationTransitionState(endpoint, colorSaturationTransitionState); colorSaturationTransitionState->finalValue = saturation; - colorSaturationTransitionState->stepsRemaining = max(transitionTime, 1); + colorSaturationTransitionState->stepsRemaining = std::max(transitionTime, 1); colorSaturationTransitionState->stepsTotal = colorSaturationTransitionState->stepsRemaining; colorSaturationTransitionState->timeRemaining = transitionTime; colorSaturationTransitionState->transitionTime = transitionTime; @@ -1363,7 +1363,7 @@ Status ColorControlServer::moveToHueAndSaturation(uint16_t hue, uint8_t saturati } colorHueTransitionState->up = moveUp; - colorHueTransitionState->stepsRemaining = max(transitionTime, 1); + colorHueTransitionState->stepsRemaining = std::max(transitionTime, 1); colorHueTransitionState->stepsTotal = colorHueTransitionState->stepsRemaining; colorHueTransitionState->timeRemaining = transitionTime; colorHueTransitionState->transitionTime = transitionTime; @@ -1614,7 +1614,7 @@ bool ColorControlServer::moveToHueCommand(app::CommandHandler * commandObj, cons colorHueTransitionState->finalHue = static_cast(hue); } - colorHueTransitionState->stepsRemaining = max(transitionTime, 1); + colorHueTransitionState->stepsRemaining = std::max(transitionTime, 1); colorHueTransitionState->stepsTotal = colorHueTransitionState->stepsRemaining; colorHueTransitionState->timeRemaining = transitionTime; colorHueTransitionState->transitionTime = transitionTime; @@ -1758,7 +1758,7 @@ bool ColorControlServer::stepHueCommand(app::CommandHandler * commandObj, const } } - colorHueTransitionState->stepsRemaining = max(transitionTime, 1); + colorHueTransitionState->stepsRemaining = std::max(transitionTime, 1); colorHueTransitionState->stepsTotal = colorHueTransitionState->stepsRemaining; colorHueTransitionState->timeRemaining = transitionTime; colorHueTransitionState->transitionTime = transitionTime; @@ -1934,7 +1934,7 @@ bool ColorControlServer::stepSaturationCommand(app::CommandHandler * commandObj, { colorSaturationTransitionState->finalValue = subtractSaturation(currentSaturation, stepSize); } - colorSaturationTransitionState->stepsRemaining = max(transitionTime, 1); + colorSaturationTransitionState->stepsRemaining = std::max(transitionTime, 1); colorSaturationTransitionState->stepsTotal = colorSaturationTransitionState->stepsRemaining; colorSaturationTransitionState->timeRemaining = transitionTime; colorSaturationTransitionState->transitionTime = transitionTime; @@ -2276,7 +2276,7 @@ Status ColorControlServer::moveToColor(uint16_t colorX, uint16_t colorY, uint16_ Attributes::CurrentX::Get(endpoint, &(colorXTransitionState->initialValue)); Attributes::CurrentX::Get(endpoint, &(colorXTransitionState->currentValue)); colorXTransitionState->finalValue = colorX; - colorXTransitionState->stepsRemaining = max(transitionTime, 1); + colorXTransitionState->stepsRemaining = std::max(transitionTime, 1); colorXTransitionState->stepsTotal = colorXTransitionState->stepsRemaining; colorXTransitionState->timeRemaining = transitionTime; colorXTransitionState->transitionTime = transitionTime; @@ -2402,7 +2402,7 @@ bool ColorControlServer::moveColorCommand(app::CommandHandler * commandObj, cons colorYTransitionState->lowLimit = MIN_CIE_XY_VALUE; colorYTransitionState->highLimit = MAX_CIE_XY_VALUE; - SetQuietReportRemainingTime(endpoint, max(transitionTimeX, transitionTimeY), true /* isNewTransition */); + SetQuietReportRemainingTime(endpoint, std::max(transitionTimeX, transitionTimeY), true /* isNewTransition */); // kick off the state machine: scheduleTimerCallbackMs(configureXYEventControl(endpoint), TRANSITION_UPDATE_TIME_MS.count()); @@ -2463,7 +2463,7 @@ bool ColorControlServer::stepColorCommand(app::CommandHandler * commandObj, cons colorXTransitionState->initialValue = currentColorX; colorXTransitionState->currentValue = currentColorX; colorXTransitionState->finalValue = colorX; - colorXTransitionState->stepsRemaining = max(transitionTime, 1); + colorXTransitionState->stepsRemaining = std::max(transitionTime, 1); colorXTransitionState->stepsTotal = colorXTransitionState->stepsRemaining; colorXTransitionState->timeRemaining = transitionTime; colorXTransitionState->transitionTime = transitionTime; @@ -2507,7 +2507,7 @@ void ColorControlServer::updateXYCommand(EndpointId endpoint) bool isXTransitionDone = computeNewColor16uValue(colorXTransitionState); bool isYTransitionDone = computeNewColor16uValue(colorYTransitionState); - SetQuietReportRemainingTime(endpoint, max(colorXTransitionState->timeRemaining, colorYTransitionState->timeRemaining)); + SetQuietReportRemainingTime(endpoint, std::max(colorXTransitionState->timeRemaining, colorYTransitionState->timeRemaining)); if (isXTransitionDone && isYTransitionDone) { @@ -2607,7 +2607,7 @@ Status ColorControlServer::moveToColorTemp(EndpointId aEndpoint, uint16_t colorT Attributes::ColorTemperatureMireds::Get(endpoint, &(colorTempTransitionState->currentValue)); colorTempTransitionState->finalValue = colorTemperature; - colorTempTransitionState->stepsRemaining = max(transitionTime, 1); + colorTempTransitionState->stepsRemaining = std::max(transitionTime, 1); colorTempTransitionState->stepsTotal = colorTempTransitionState->stepsRemaining; colorTempTransitionState->timeRemaining = transitionTime; colorTempTransitionState->transitionTime = transitionTime; @@ -2990,7 +2990,7 @@ bool ColorControlServer::stepColorTempCommand(app::CommandHandler * commandObj, colorTempTransitionState->finalValue = static_cast(finalValue32u); } } - colorTempTransitionState->stepsRemaining = max(transitionTime, 1); + colorTempTransitionState->stepsRemaining = std::max(transitionTime, 1); colorTempTransitionState->stepsTotal = colorTempTransitionState->stepsRemaining; colorTempTransitionState->timeRemaining = transitionTime; colorTempTransitionState->transitionTime = transitionTime; diff --git a/src/app/clusters/network-commissioning/network-commissioning.cpp b/src/app/clusters/network-commissioning/network-commissioning.cpp index 6bb3356b89..ea73b8ff23 100644 --- a/src/app/clusters/network-commissioning/network-commissioning.cpp +++ b/src/app/clusters/network-commissioning/network-commissioning.cpp @@ -233,7 +233,7 @@ class ThreadScanResponseToTLV : public chip::app::DataModel::EncodableToTLV CHIP_ERROR ThreadScanResponseToTLV::LoadResponses(Platform::ScopedMemoryBuffer & scanResponseArray, Span & validResponses) const { - VerifyOrReturnError(scanResponseArray.Alloc(chip::min(mNetworks->Count(), kMaxNetworksInScanResponse)), CHIP_ERROR_NO_MEMORY); + VerifyOrReturnError(scanResponseArray.Alloc(std::min(mNetworks->Count(), kMaxNetworksInScanResponse)), CHIP_ERROR_NO_MEMORY); ThreadScanResponse scanResponse; size_t scanResponseArrayLength = 0; diff --git a/src/app/clusters/ota-requestor/DefaultOTARequestorDriver.cpp b/src/app/clusters/ota-requestor/DefaultOTARequestorDriver.cpp index d3efeaee6f..f8f54f940a 100644 --- a/src/app/clusters/ota-requestor/DefaultOTARequestorDriver.cpp +++ b/src/app/clusters/ota-requestor/DefaultOTARequestorDriver.cpp @@ -219,17 +219,17 @@ CHIP_ERROR DefaultOTARequestorDriver::UpdateNotFound(UpdateNotFoundReason reason case UpdateNotFoundReason::kUpToDate: break; case UpdateNotFoundReason::kBusy: { - status = ScheduleQueryRetry(true, chip::max(kDefaultDelayedActionTime, delay)); + status = ScheduleQueryRetry(true, std::max(kDefaultDelayedActionTime, delay)); if (status == CHIP_ERROR_MAX_RETRY_EXCEEDED) { // If max retry exceeded with current provider, try a different provider - status = ScheduleQueryRetry(false, chip::max(kDefaultDelayedActionTime, delay)); + status = ScheduleQueryRetry(false, std::max(kDefaultDelayedActionTime, delay)); } break; } case UpdateNotFoundReason::kNotAvailable: { // Schedule a query only if a different provider is available - status = ScheduleQueryRetry(false, chip::max(kDefaultDelayedActionTime, delay)); + status = ScheduleQueryRetry(false, std::max(kDefaultDelayedActionTime, delay)); break; } } diff --git a/src/app/clusters/scenes-server/SceneTableImpl.cpp b/src/app/clusters/scenes-server/SceneTableImpl.cpp index 81cd05cd18..24d300e8f5 100644 --- a/src/app/clusters/scenes-server/SceneTableImpl.cpp +++ b/src/app/clusters/scenes-server/SceneTableImpl.cpp @@ -276,7 +276,7 @@ struct FabricSceneData : public PersistentData ReturnErrorOnFailure(reader.EnterContainer(fabricSceneContainer)); ReturnErrorOnFailure(reader.Next(TLV::ContextTag(TagScene::kSceneCount))); ReturnErrorOnFailure(reader.Get(scene_count)); - scene_count = min(scene_count, static_cast(max_scenes_per_fabric)); + scene_count = std::min(scene_count, static_cast(max_scenes_per_fabric)); ReturnErrorOnFailure(reader.Next(TLV::kTLVType_Array, TLV::ContextTag(TagScene::kStorageIDArray))); TLV::TLVType sceneMapContainer; ReturnErrorOnFailure(reader.EnterContainer(sceneMapContainer)); @@ -577,7 +577,7 @@ CHIP_ERROR DefaultSceneTableImpl::GetRemainingCapacity(FabricIndex fabric_index, remaining_capacity_fabric = static_cast(mMaxScenesPerFabric - fabric.scene_count); } - capacity = min(remaining_capacity_fabric, remaining_capacity_global); + capacity = std::min(remaining_capacity_fabric, remaining_capacity_global); return CHIP_NO_ERROR; } diff --git a/src/app/clusters/thread-network-diagnostics-server/thread-network-diagnostics-provider.cpp b/src/app/clusters/thread-network-diagnostics-server/thread-network-diagnostics-provider.cpp index 69ec2a5e13..bf056d2e37 100644 --- a/src/app/clusters/thread-network-diagnostics-server/thread-network-diagnostics-provider.cpp +++ b/src/app/clusters/thread-network-diagnostics-server/thread-network-diagnostics-provider.cpp @@ -214,7 +214,7 @@ CHIP_ERROR WriteThreadNetworkDiagnosticAttributeToTlv(AttributeId attributeId, a } else { - lastRssi.SetNonNull(min(static_cast(0), neighInfo.mLastRssi)); + lastRssi.SetNonNull(std::min(static_cast(0), neighInfo.mLastRssi)); } neighborTable.averageRssi = averageRssi; diff --git a/src/ble/BLEEndPoint.cpp b/src/ble/BLEEndPoint.cpp index d8e2a7b2a4..a035626781 100644 --- a/src/ble/BLEEndPoint.cpp +++ b/src/ble/BLEEndPoint.cpp @@ -1001,7 +1001,7 @@ CHIP_ERROR BLEEndPoint::HandleCapabilitiesRequestReceived(PacketBufferHandle && if (mtu > 0) // If one or both device knows connection's MTU... { resp.mFragmentSize = - chip::min(static_cast(mtu - 3), BtpEngine::sMaxFragmentSize); // Reserve 3 bytes of MTU for ATT header. + std::min(static_cast(mtu - 3), BtpEngine::sMaxFragmentSize); // Reserve 3 bytes of MTU for ATT header. } else // Else, if neither device knows MTU... { @@ -1012,7 +1012,7 @@ CHIP_ERROR BLEEndPoint::HandleCapabilitiesRequestReceived(PacketBufferHandle && // Select local and remote max receive window size based on local resources available for both incoming writes AND // GATT confirmations. mRemoteReceiveWindowSize = mLocalReceiveWindowSize = mReceiveWindowMaxSize = - chip::min(req.mWindowSize, static_cast(BLE_MAX_RECEIVE_WINDOW_SIZE)); + std::min(req.mWindowSize, static_cast(BLE_MAX_RECEIVE_WINDOW_SIZE)); resp.mWindowSize = mReceiveWindowMaxSize; ChipLogProgress(Ble, "local and remote recv window sizes = %u", resp.mWindowSize); @@ -1068,7 +1068,7 @@ CHIP_ERROR BLEEndPoint::HandleCapabilitiesResponseReceived(PacketBufferHandle && } // Set fragment size as minimum of (reported ATT MTU, BTP characteristic size) - resp.mFragmentSize = chip::min(resp.mFragmentSize, BtpEngine::sMaxFragmentSize); + resp.mFragmentSize = std::min(resp.mFragmentSize, BtpEngine::sMaxFragmentSize); mBtpEngine.SetRxFragmentSize(resp.mFragmentSize); mBtpEngine.SetTxFragmentSize(resp.mFragmentSize); diff --git a/src/ble/BtpEngine.cpp b/src/ble/BtpEngine.cpp index 75958169a7..4f52b59906 100644 --- a/src/ble/BtpEngine.cpp +++ b/src/ble/BtpEngine.cpp @@ -274,7 +274,7 @@ CHIP_ERROR BtpEngine::HandleCharacteristicReceived(System::PacketBufferHandle && // mRxFragmentSize may be smaller than the characteristic size. Make sure // we're not truncating to a data length smaller than what we have already consumed. VerifyOrExit(reader.OctetsRead() <= mRxFragmentSize, err = BLE_ERROR_REASSEMBLER_INCORRECT_STATE); - data->SetDataLength(chip::min(data->DataLength(), static_cast(mRxFragmentSize))); + data->SetDataLength(std::min(data->DataLength(), static_cast(mRxFragmentSize))); // Now mark the bytes we consumed as consumed. data->ConsumeHead(static_cast(reader.OctetsRead())); diff --git a/src/crypto/CHIPCryptoPALPSA.cpp b/src/crypto/CHIPCryptoPALPSA.cpp index 99b947c18f..ba34669a51 100644 --- a/src/crypto/CHIPCryptoPALPSA.cpp +++ b/src/crypto/CHIPCryptoPALPSA.cpp @@ -472,7 +472,7 @@ CHIP_ERROR PBKDF2_sha256::pbkdf2_sha256(const uint8_t * pass, size_t pass_length for (uint32_t blockNo = 1; key_length != 0; ++blockNo) { - uint8_t in[chip::max(kMacLength, kSpake2p_Max_PBKDF_Salt_Length + 4)]; + uint8_t in[std::max(kMacLength, kSpake2p_Max_PBKDF_Salt_Length + 4)]; size_t inLength = salt_length + 4; uint8_t out[kMacLength]; size_t outLength; @@ -495,7 +495,7 @@ CHIP_ERROR PBKDF2_sha256::pbkdf2_sha256(const uint8_t * pass, size_t pass_length inLength = outLength; } - const size_t usedKeyLength = chip::min(key_length, kMacLength); + const size_t usedKeyLength = std::min(key_length, kMacLength); memcpy(key, result, usedKeyLength); key += usedKeyLength; key_length -= usedKeyLength; diff --git a/src/inet/IPAddress-StringFuncts.cpp b/src/inet/IPAddress-StringFuncts.cpp index 13bbb4e0f8..7022b44a6a 100644 --- a/src/inet/IPAddress-StringFuncts.cpp +++ b/src/inet/IPAddress-StringFuncts.cpp @@ -23,6 +23,7 @@ * */ +#include #include #include #include @@ -57,8 +58,8 @@ char * IPAddress::ToString(char * buf, uint32_t bufSize) const // socklen_t is sometimes signed, sometimes not, so the only safe way to do // this is to promote everything to an unsigned type that's known to be big // enough for everything, then cast back to uint32_t after taking the min. - bufSize = - static_cast(min(static_cast(std::numeric_limits::max()), static_cast(bufSize))); + bufSize = static_cast( + std::min(static_cast(std::numeric_limits::max()), static_cast(bufSize))); #if INET_CONFIG_ENABLE_IPV4 if (IsIPv4()) { diff --git a/src/inet/tests/TestInetLayerCommon.cpp b/src/inet/tests/TestInetLayerCommon.cpp index b1f0172bea..6f8545ba39 100644 --- a/src/inet/tests/TestInetLayerCommon.cpp +++ b/src/inet/tests/TestInetLayerCommon.cpp @@ -164,7 +164,7 @@ static PacketBufferHandle MakeDataBuffer(size_t aDesiredLength, size_t aPatternS PacketBufferHandle lBuffer = PacketBufferHandle::New(aDesiredLength); VerifyOrReturnError(!lBuffer.IsNull(), lBuffer); - aDesiredLength = min(lBuffer->MaxDataLength(), aDesiredLength); + aDesiredLength = std::min(lBuffer->MaxDataLength(), aDesiredLength); FillDataBufferPattern(lBuffer->Start(), aDesiredLength, aPatternStartOffset, aFirstValue); diff --git a/src/inet/tests/inet-layer-test-tool.cpp b/src/inet/tests/inet-layer-test-tool.cpp index 0c1158a9ed..ff0eae8941 100644 --- a/src/inet/tests/inet-layer-test-tool.cpp +++ b/src/inet/tests/inet-layer-test-tool.cpp @@ -777,7 +777,7 @@ void DriveSend() if (sTestState.mStats.mTransmit.mActual < sTestState.mStats.mTransmit.mExpected) { const uint32_t lRemaining = (sTestState.mStats.mTransmit.mExpected - sTestState.mStats.mTransmit.mActual); - const uint32_t lSendSize = chip::min(lRemaining, static_cast(gSendSize)); + const uint32_t lSendSize = std::min(lRemaining, static_cast(gSendSize)); // gSendSize is uint16_t, so this cast is safe: the value has to be // in the uint16_t range. diff --git a/src/lib/core/OTAImageHeader.cpp b/src/lib/core/OTAImageHeader.cpp index 68942d919a..ab4b65635b 100644 --- a/src/lib/core/OTAImageHeader.cpp +++ b/src/lib/core/OTAImageHeader.cpp @@ -102,7 +102,7 @@ CHIP_ERROR OTAImageHeaderParser::AccumulateAndDecode(ByteSpan & buffer, OTAImage void OTAImageHeaderParser::Append(ByteSpan & buffer, uint32_t numBytes) { - numBytes = chip::min(numBytes, static_cast(buffer.size())); + numBytes = std::min(numBytes, static_cast(buffer.size())); memcpy(&mBuffer[mBufferOffset], buffer.data(), numBytes); mBufferOffset += numBytes; buffer = buffer.SubSpan(numBytes); diff --git a/src/lib/core/tests/TestOTAImageHeader.cpp b/src/lib/core/tests/TestOTAImageHeader.cpp index bee9da3978..03bee0dbb7 100644 --- a/src/lib/core/tests/TestOTAImageHeader.cpp +++ b/src/lib/core/tests/TestOTAImageHeader.cpp @@ -167,7 +167,7 @@ TEST_F(TestOTAImageHeader, TestSmallBlocks) for (size_t offset = 0; offset < kImageSize && error == CHIP_ERROR_BUFFER_TOO_SMALL; offset += blockSize) { - ByteSpan block(&kOtaImage[offset], chip::min(kImageSize - offset, blockSize)); + ByteSpan block(&kOtaImage[offset], std::min(kImageSize - offset, blockSize)); error = parser.AccumulateAndDecode(block, header); } diff --git a/src/lib/dnssd/ServiceNaming.cpp b/src/lib/dnssd/ServiceNaming.cpp index 8ec86a1bfb..405e10a69c 100644 --- a/src/lib/dnssd/ServiceNaming.cpp +++ b/src/lib/dnssd/ServiceNaming.cpp @@ -63,7 +63,7 @@ CHIP_ERROR ExtractIdFromInstanceName(const char * name, PeerId * peerId) // Check what we have a separator where we expect. ReturnErrorCodeIf(name[fabricIdStringLength] != '-', CHIP_ERROR_WRONG_NODE_ID); - static constexpr size_t bufferSize = max(fabricIdByteLength, nodeIdByteLength); + static constexpr size_t bufferSize = std::max(fabricIdByteLength, nodeIdByteLength); uint8_t buf[bufferSize]; ReturnErrorCodeIf(Encoding::HexToBytes(name, fabricIdStringLength, buf, bufferSize) == 0, CHIP_ERROR_WRONG_NODE_ID); diff --git a/src/lib/support/BufferReader.h b/src/lib/support/BufferReader.h index f37667453e..ac9c714535 100644 --- a/src/lib/support/BufferReader.h +++ b/src/lib/support/BufferReader.h @@ -302,7 +302,7 @@ class Reader */ Reader & Skip(size_t len) { - len = ::chip::min(len, mAvailable); + len = std::min(len, mAvailable); mReadPtr += len; mAvailable = static_cast(mAvailable - len); return *this; diff --git a/src/lib/support/CodeUtils.h b/src/lib/support/CodeUtils.h index fb659c4793..0142bc8544 100644 --- a/src/lib/support/CodeUtils.h +++ b/src/lib/support/CodeUtils.h @@ -131,30 +131,6 @@ #include -namespace chip { - -// Generic min() and max() functions -// -template -constexpr inline const _T & min(const _T & a, const _T & b) -{ - if (b < a) - return b; - - return a; -} - -template -constexpr inline const _T & max(const _T & a, const _T & b) -{ - if (a < b) - return b; - - return a; -} - -} // namespace chip - /** * @def ReturnErrorOnFailure(expr) * diff --git a/src/lib/support/SafeString.h b/src/lib/support/SafeString.h index 4d85280804..cf75ba5563 100644 --- a/src/lib/support/SafeString.h +++ b/src/lib/support/SafeString.h @@ -23,9 +23,11 @@ #pragma once -#include +#include #include +#include + namespace chip { /** @@ -48,7 +50,7 @@ template constexpr size_t MaxStringLength(const char (&)[FirstLength], RestOfTypes &&... aArgs) { // Subtract 1 because we are not counting the null-terminator. - return max(FirstLength - 1, MaxStringLength(std::forward(aArgs)...)); + return std::max(FirstLength - 1, MaxStringLength(std::forward(aArgs)...)); } /** diff --git a/src/lib/support/ZclString.cpp b/src/lib/support/ZclString.cpp index 3482cd4303..3bbdb25179 100644 --- a/src/lib/support/ZclString.cpp +++ b/src/lib/support/ZclString.cpp @@ -34,7 +34,7 @@ CHIP_ERROR MakeZclCharString(MutableByteSpan & buffer, const char * cString) return CHIP_ERROR_INBOUND_MESSAGE_TOO_BIG; } size_t len = strlen(cString); - size_t availableStorage = min(buffer.size() - 1, kBufferMaximumSize); + size_t availableStorage = std::min(buffer.size() - 1, kBufferMaximumSize); if (len > availableStorage) { buffer.data()[0] = 0; diff --git a/src/platform/ASR/ASRUtils.cpp b/src/platform/ASR/ASRUtils.cpp index f65c6ecb11..5095d22f62 100644 --- a/src/platform/ASR/ASRUtils.cpp +++ b/src/platform/ASR/ASRUtils.cpp @@ -235,7 +235,7 @@ CHIP_ERROR ASRUtils::GetWiFiStationProvision(Internal::DeviceNetworkInfo & netIn netInfo.NetworkId = kWiFiStationNetworkId; netInfo.FieldPresent.NetworkId = true; memcpy(netInfo.WiFiSSID, stationConfig.wifi_ssid, - min(strlen(reinterpret_cast(stationConfig.wifi_ssid)) + 1, sizeof(netInfo.WiFiSSID))); + std::min(strlen(reinterpret_cast(stationConfig.wifi_ssid)) + 1, sizeof(netInfo.WiFiSSID))); // Enforce that netInfo wifiSSID is null terminated netInfo.WiFiSSID[kMaxWiFiSSIDLength] = '\0'; @@ -243,7 +243,7 @@ CHIP_ERROR ASRUtils::GetWiFiStationProvision(Internal::DeviceNetworkInfo & netIn if (includeCredentials) { static_assert(sizeof(netInfo.WiFiKey) < 255, "Our min might not fit in netInfo.WiFiKeyLen"); - netInfo.WiFiKeyLen = static_cast(min(strlen((char *) stationConfig.wifi_key), sizeof(netInfo.WiFiKey))); + netInfo.WiFiKeyLen = static_cast(std::min(strlen((char *) stationConfig.wifi_key), sizeof(netInfo.WiFiKey))); memcpy(netInfo.WiFiKey, stationConfig.wifi_key, netInfo.WiFiKeyLen); } diff --git a/src/platform/Darwin/DnssdContexts.cpp b/src/platform/Darwin/DnssdContexts.cpp index e6b590d09e..de8048035f 100644 --- a/src/platform/Darwin/DnssdContexts.cpp +++ b/src/platform/Darwin/DnssdContexts.cpp @@ -722,7 +722,7 @@ void ResolveContext::OnNewInterface(uint32_t interfaceId, const char * fullname, size_t len = *txtRecordIter; ++txtRecordIter; --remainingLen; - len = min(len, remainingLen); + len = std::min(len, remainingLen); chip::Span bytes(txtRecordIter, len); if (txtString.size() > 0) { diff --git a/src/platform/ESP32/DiagnosticDataProviderImpl.cpp b/src/platform/ESP32/DiagnosticDataProviderImpl.cpp index fc2992f20d..9be535fb61 100644 --- a/src/platform/ESP32/DiagnosticDataProviderImpl.cpp +++ b/src/platform/ESP32/DiagnosticDataProviderImpl.cpp @@ -260,7 +260,7 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetNetworkInterfaces(NetworkInterface ** } else { - ipv6_addr_count = static_cast(min(addr_count, static_cast(kMaxIPv6AddrCount))); + ipv6_addr_count = static_cast(std::min(addr_count, static_cast(kMaxIPv6AddrCount))); } for (uint8_t idx = 0; idx < ipv6_addr_count; ++idx) { diff --git a/src/platform/ESP32/ESP32Utils.cpp b/src/platform/ESP32/ESP32Utils.cpp index ffa45ee722..e66007a0a8 100644 --- a/src/platform/ESP32/ESP32Utils.cpp +++ b/src/platform/ESP32/ESP32Utils.cpp @@ -241,7 +241,7 @@ CHIP_ERROR ESP32Utils::GetWiFiStationProvision(Internal::DeviceNetworkInfo & net netInfo.NetworkId = kWiFiStationNetworkId; netInfo.FieldPresent.NetworkId = true; memcpy(netInfo.WiFiSSID, stationConfig.sta.ssid, - min(strlen(reinterpret_cast(stationConfig.sta.ssid)) + 1, sizeof(netInfo.WiFiSSID))); + std::min(strlen(reinterpret_cast(stationConfig.sta.ssid)) + 1, sizeof(netInfo.WiFiSSID))); // Enforce that netInfo wifiSSID is null terminated netInfo.WiFiSSID[kMaxWiFiSSIDLength] = '\0'; @@ -249,7 +249,7 @@ CHIP_ERROR ESP32Utils::GetWiFiStationProvision(Internal::DeviceNetworkInfo & net if (includeCredentials) { static_assert(sizeof(netInfo.WiFiKey) < 255, "Our min might not fit in netInfo.WiFiKeyLen"); - netInfo.WiFiKeyLen = static_cast(min(strlen((char *) stationConfig.sta.password), sizeof(netInfo.WiFiKey))); + netInfo.WiFiKeyLen = static_cast(std::min(strlen((char *) stationConfig.sta.password), sizeof(netInfo.WiFiKey))); memcpy(netInfo.WiFiKey, stationConfig.sta.password, netInfo.WiFiKeyLen); } @@ -268,7 +268,7 @@ CHIP_ERROR ESP32Utils::SetWiFiStationProvision(const Internal::DeviceNetworkInfo ReturnErrorOnFailure(ESP32Utils::EnableStationMode()); // Enforce that wifiSSID is null terminated before copying it - memcpy(wifiSSID, netInfo.WiFiSSID, min(netInfoSSIDLen + 1, sizeof(wifiSSID))); + memcpy(wifiSSID, netInfo.WiFiSSID, std::min(netInfoSSIDLen + 1, sizeof(wifiSSID))); if (netInfoSSIDLen + 1 < sizeof(wifiSSID)) { wifiSSID[netInfoSSIDLen] = '\0'; @@ -280,8 +280,8 @@ CHIP_ERROR ESP32Utils::SetWiFiStationProvision(const Internal::DeviceNetworkInfo // Initialize an ESP wifi_config_t structure based on the new provision information. memset(&wifiConfig, 0, sizeof(wifiConfig)); - memcpy(wifiConfig.sta.ssid, wifiSSID, min(strlen(wifiSSID) + 1, sizeof(wifiConfig.sta.ssid))); - memcpy(wifiConfig.sta.password, netInfo.WiFiKey, min((size_t) netInfo.WiFiKeyLen, sizeof(wifiConfig.sta.password))); + memcpy(wifiConfig.sta.ssid, wifiSSID, std::min(strlen(wifiSSID) + 1, sizeof(wifiConfig.sta.ssid))); + memcpy(wifiConfig.sta.password, netInfo.WiFiKey, std::min((size_t) netInfo.WiFiKeyLen, sizeof(wifiConfig.sta.password))); wifiConfig.sta.scan_method = WIFI_ALL_CHANNEL_SCAN; wifiConfig.sta.sort_method = WIFI_CONNECT_AP_BY_SIGNAL; diff --git a/src/platform/Infineon/PSOC6/ConnectivityManagerImpl.cpp b/src/platform/Infineon/PSOC6/ConnectivityManagerImpl.cpp index a2f7fae9f3..6d0a1907a8 100644 --- a/src/platform/Infineon/PSOC6/ConnectivityManagerImpl.cpp +++ b/src/platform/Infineon/PSOC6/ConnectivityManagerImpl.cpp @@ -229,9 +229,9 @@ CHIP_ERROR ConnectivityManagerImpl::_Init() wifi_config_t wifiConfig; memset(&wifiConfig, 0, sizeof(wifiConfig)); memcpy(wifiConfig.sta.ssid, CHIP_DEVICE_CONFIG_DEFAULT_STA_SSID, - min(strlen(CHIP_DEVICE_CONFIG_DEFAULT_STA_SSID), sizeof(wifiConfig.sta.ssid))); + std::min(strlen(CHIP_DEVICE_CONFIG_DEFAULT_STA_SSID), sizeof(wifiConfig.sta.ssid))); memcpy(wifiConfig.sta.password, CHIP_DEVICE_CONFIG_DEFAULT_STA_PASSWORD, - min(strlen(CHIP_DEVICE_CONFIG_DEFAULT_STA_PASSWORD), sizeof(wifiConfig.sta.password))); + std::min(strlen(CHIP_DEVICE_CONFIG_DEFAULT_STA_PASSWORD), sizeof(wifiConfig.sta.password))); wifiConfig.sta.security = CHIP_DEVICE_CONFIG_DEFAULT_STA_SECURITY; err = Internal::PSOC6Utils::p6_wifi_set_config(WIFI_IF_STA, &wifiConfig); SuccessOrExit(err); diff --git a/src/platform/Infineon/PSOC6/PSOC6Utils.cpp b/src/platform/Infineon/PSOC6/PSOC6Utils.cpp index c65a29f6a9..3b1b906aa6 100644 --- a/src/platform/Infineon/PSOC6/PSOC6Utils.cpp +++ b/src/platform/Infineon/PSOC6/PSOC6Utils.cpp @@ -335,7 +335,7 @@ CHIP_ERROR PSOC6Utils::GetWiFiStationProvision(Internal::DeviceNetworkInfo & net netInfo.NetworkId = kWiFiStationNetworkId; netInfo.FieldPresent.NetworkId = true; memcpy(netInfo.WiFiSSID, stationConfig.sta.ssid, - min(strlen(reinterpret_cast(stationConfig.sta.ssid)) + 1, sizeof(netInfo.WiFiSSID))); + std::min(strlen(reinterpret_cast(stationConfig.sta.ssid)) + 1, sizeof(netInfo.WiFiSSID))); // Enforce that netInfo wifiSSID is null terminated netInfo.WiFiSSID[kMaxWiFiSSIDLength] = '\0'; @@ -343,7 +343,7 @@ CHIP_ERROR PSOC6Utils::GetWiFiStationProvision(Internal::DeviceNetworkInfo & net if (includeCredentials) { static_assert(sizeof(netInfo.WiFiKey) < 255, "Our min might not fit in netInfo.WiFiKeyLen"); - netInfo.WiFiKeyLen = static_cast(min(strlen((char *) stationConfig.sta.password), sizeof(netInfo.WiFiKey))); + netInfo.WiFiKeyLen = static_cast(std::min(strlen((char *) stationConfig.sta.password), sizeof(netInfo.WiFiKey))); memcpy(netInfo.WiFiKey, stationConfig.sta.password, netInfo.WiFiKeyLen); } @@ -365,7 +365,7 @@ CHIP_ERROR PSOC6Utils::SetWiFiStationProvision(const Internal::DeviceNetworkInfo SuccessOrExit(err); // Enforce that wifiSSID is null terminated before copying it - memcpy(wifiSSID, netInfo.WiFiSSID, min(netInfoSSIDLen + 1, sizeof(wifiSSID))); + memcpy(wifiSSID, netInfo.WiFiSSID, std::min(netInfoSSIDLen + 1, sizeof(wifiSSID))); if (netInfoSSIDLen + 1 < sizeof(wifiSSID)) { wifiSSID[netInfoSSIDLen] = '\0'; @@ -505,16 +505,16 @@ void PSOC6Utils::populate_wifi_config_t(wifi_config_t * wifi_config, wifi_interf if (interface == WIFI_IF_STA || interface == WIFI_IF_STA_AP) { memset(&wifi_config->sta, 0, sizeof(wifi_config_sta_t)); - memcpy(wifi_config->sta.ssid, ssid, chip::min(strlen((char *) ssid) + 1, sizeof(cy_wcm_ssid_t))); - memcpy(wifi_config->sta.password, password, chip::min(strlen((char *) password) + 1, sizeof(cy_wcm_ssid_t))); + memcpy(wifi_config->sta.ssid, ssid, std::min(strlen((char *) ssid) + 1, sizeof(cy_wcm_ssid_t))); + memcpy(wifi_config->sta.password, password, std::min(strlen((char *) password) + 1, sizeof(cy_wcm_ssid_t))); wifi_config->sta.security = security; } if (interface == WIFI_IF_AP || interface == WIFI_IF_STA_AP) { memset(&wifi_config->ap, 0, sizeof(wifi_config_ap_t)); - memcpy(wifi_config->ap.ssid, ssid, chip::min(strlen((char *) ssid) + 1, sizeof(cy_wcm_ssid_t))); - memcpy(wifi_config->ap.password, password, chip::min(strlen((char *) password) + 1, sizeof(cy_wcm_ssid_t))); + memcpy(wifi_config->ap.ssid, ssid, std::min(strlen((char *) ssid) + 1, sizeof(cy_wcm_ssid_t))); + memcpy(wifi_config->ap.password, password, std::min(strlen((char *) password) + 1, sizeof(cy_wcm_ssid_t))); wifi_config->ap.security = security; } } diff --git a/src/platform/android/AndroidConfig.cpp b/src/platform/android/AndroidConfig.cpp index afca2b43f3..510008f441 100644 --- a/src/platform/android/AndroidConfig.cpp +++ b/src/platform/android/AndroidConfig.cpp @@ -280,7 +280,7 @@ CHIP_ERROR AndroidConfig::ReadConfigValueBin(Key key, uint8_t * buf, size_t bufS } outLen = static_cast(env->GetArrayLength(javaValue)); - memcpy(buf, elements, min(outLen, bufSize)); + memcpy(buf, elements, std::min(outLen, bufSize)); env->ReleaseByteArrayElements(javaValue, elements, 0); diff --git a/src/platform/mt793x/DnssdContexts.cpp b/src/platform/mt793x/DnssdContexts.cpp index c554c01916..5c0e6a0405 100644 --- a/src/platform/mt793x/DnssdContexts.cpp +++ b/src/platform/mt793x/DnssdContexts.cpp @@ -451,7 +451,7 @@ void ResolveContext::OnNewInterface(uint32_t interfaceId, const char * fullname, size_t len = *txtRecordIter; ++txtRecordIter; --remainingLen; - len = min(len, remainingLen); + len = std::min(len, remainingLen); chip::Span bytes(txtRecordIter, len); if (txtString.size() > 0) { diff --git a/src/platform/nxp/common/ota/OTATlvProcessor.cpp b/src/platform/nxp/common/ota/OTATlvProcessor.cpp index 66a080135b..ad41d0f42e 100644 --- a/src/platform/nxp/common/ota/OTATlvProcessor.cpp +++ b/src/platform/nxp/common/ota/OTATlvProcessor.cpp @@ -40,7 +40,7 @@ CHIP_ERROR OTATlvProcessor::ApplyAction() CHIP_ERROR OTATlvProcessor::Process(ByteSpan & block) { CHIP_ERROR status = CHIP_NO_ERROR; - uint32_t bytes = chip::min(mLength - mProcessedLength, static_cast(block.size())); + uint32_t bytes = std::min(mLength - mProcessedLength, static_cast(block.size())); ByteSpan relevantData = block.SubSpan(0, bytes); status = ProcessInternal(relevantData); @@ -96,7 +96,7 @@ void OTADataAccumulator::Clear() CHIP_ERROR OTADataAccumulator::Accumulate(ByteSpan & block) { - uint32_t numBytes = chip::min(mThreshold - mBufferOffset, static_cast(block.size())); + uint32_t numBytes = std::min(mThreshold - mBufferOffset, static_cast(block.size())); memcpy(&mBuffer[mBufferOffset], block.data(), numBytes); mBufferOffset += numBytes; block = block.SubSpan(numBytes); diff --git a/src/platform/silabs/MigrationManager.cpp b/src/platform/silabs/MigrationManager.cpp index f78facc938..d9bba0b249 100644 --- a/src/platform/silabs/MigrationManager.cpp +++ b/src/platform/silabs/MigrationManager.cpp @@ -57,7 +57,7 @@ void MigrationManager::applyMigrations() if (lastMigationGroupDone < migrationTable[i].migrationGroup) { (*migrationTable[i].migrationFunc)(); - completedMigrationGroup = max(migrationTable[i].migrationGroup, completedMigrationGroup); + completedMigrationGroup = std::max(migrationTable[i].migrationGroup, completedMigrationGroup); } } SilabsConfig::WriteConfigValue(SilabsConfig::kConfigKey_MigrationCounter, completedMigrationGroup); diff --git a/src/platform/silabs/multi-ota/OTATlvProcessor.cpp b/src/platform/silabs/multi-ota/OTATlvProcessor.cpp index 91a748c077..e6601449fa 100644 --- a/src/platform/silabs/multi-ota/OTATlvProcessor.cpp +++ b/src/platform/silabs/multi-ota/OTATlvProcessor.cpp @@ -37,7 +37,7 @@ constexpr uint8_t au8Iv[] = { 0x00, 0x00, 0x00, 0x10, 0x11, 0x12, 0x13, 0x14, 0x CHIP_ERROR OTATlvProcessor::Process(ByteSpan & block) { CHIP_ERROR status = CHIP_NO_ERROR; - uint32_t bytes = chip::min(mLength - mProcessedLength, static_cast(block.size())); + uint32_t bytes = std::min(mLength - mProcessedLength, static_cast(block.size())); ByteSpan relevantData = block.SubSpan(0, bytes); status = ProcessInternal(relevantData); @@ -92,7 +92,7 @@ void OTADataAccumulator::Clear() CHIP_ERROR OTADataAccumulator::Accumulate(ByteSpan & block) { - uint32_t numBytes = chip::min(mThreshold - mBufferOffset, static_cast(block.size())); + uint32_t numBytes = std::min(mThreshold - mBufferOffset, static_cast(block.size())); memcpy(&mBuffer[mBufferOffset], block.data(), numBytes); mBufferOffset += numBytes; block = block.SubSpan(numBytes); diff --git a/src/platform/tests/TestKeyValueStoreMgr.cpp b/src/platform/tests/TestKeyValueStoreMgr.cpp index 0429182e0c..c6b87410b7 100644 --- a/src/platform/tests/TestKeyValueStoreMgr.cpp +++ b/src/platform/tests/TestKeyValueStoreMgr.cpp @@ -249,7 +249,7 @@ TEST_F(TestKeyValueStoreMgr, AllCharactersKey) for (size_t charId = 0; charId < sizeof(allChars); charId += kKeyLength) { char testKey[kKeyLength + 1] = {}; - memcpy(testKey, &allChars[charId], chip::min(sizeof(allChars) - charId, kKeyLength)); + memcpy(testKey, &allChars[charId], std::min(sizeof(allChars) - charId, kKeyLength)); CHIP_ERROR err = KeyValueStoreMgr().Put(testKey, kTestValue); EXPECT_EQ(err, CHIP_NO_ERROR); diff --git a/src/protocols/bdx/BdxTransferSession.cpp b/src/protocols/bdx/BdxTransferSession.cpp index 0a513d7ea7..89851493ba 100644 --- a/src/protocols/bdx/BdxTransferSession.cpp +++ b/src/protocols/bdx/BdxTransferSession.cpp @@ -559,8 +559,8 @@ void TransferSession::HandleTransferInit(MessageType msgType, System::PacketBuff VerifyOrReturn(err == CHIP_NO_ERROR, PrepareStatusReport(StatusCode::kBadMessageContents)); ResolveTransferControlOptions(transferInit.TransferCtlOptions); - mTransferVersion = ::chip::min(kBdxVersion, transferInit.Version); - mTransferMaxBlockSize = ::chip::min(mMaxSupportedBlockSize, transferInit.MaxBlockSize); + mTransferVersion = std::min(kBdxVersion, transferInit.Version); + mTransferMaxBlockSize = std::min(mMaxSupportedBlockSize, transferInit.MaxBlockSize); // Accept for now, they may be changed or rejected by the peer if this is a ReceiveInit mStartOffset = transferInit.StartOffset; diff --git a/src/system/SystemPacketBuffer.h b/src/system/SystemPacketBuffer.h index 5068822c7f..8fd73b9c35 100644 --- a/src/system/SystemPacketBuffer.h +++ b/src/system/SystemPacketBuffer.h @@ -784,7 +784,7 @@ class PacketBufferWriterBase : public Writer * @param[in] aSize Maximum number of octects to write into the packet buffer. */ PacketBufferWriterBase(System::PacketBufferHandle && aPacket, size_t aSize) : - Writer(aPacket->Start() + aPacket->DataLength(), chip::min(aSize, static_cast(aPacket->AvailableDataLength()))) + Writer(aPacket->Start() + aPacket->DataLength(), std::min(aSize, static_cast(aPacket->AvailableDataLength()))) { mPacket = std::move(aPacket); } diff --git a/src/transport/raw/MessageHeader.h b/src/transport/raw/MessageHeader.h index 2752a5c86c..32ac8a5fbf 100644 --- a/src/transport/raw/MessageHeader.h +++ b/src/transport/raw/MessageHeader.h @@ -59,7 +59,7 @@ static constexpr size_t kMaxPerSpecApplicationPayloadAndMICSizeBytes = static constexpr size_t kMaxPacketBufferApplicationPayloadAndMICSizeBytes = System::PacketBuffer::kMaxSize; static constexpr size_t kMaxApplicationPayloadAndMICSizeBytes = - min(kMaxPerSpecApplicationPayloadAndMICSizeBytes, kMaxPacketBufferApplicationPayloadAndMICSizeBytes); + std::min(kMaxPerSpecApplicationPayloadAndMICSizeBytes, kMaxPacketBufferApplicationPayloadAndMICSizeBytes); } // namespace detail static constexpr size_t kMaxTagLen = 16;