Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable -Wconversion for nrfconnect platform bits. #25383

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,8 @@ void GenericThreadStackManagerImpl_OpenThread<ImplClass>::_OnNetworkScanFinished
scanResponse.lqi = aResult->mLqi;
scanResponse.extendedAddress = Encoding::BigEndian::Get64(aResult->mExtAddress.m8);
scanResponse.extendedPanId = Encoding::BigEndian::Get64(aResult->mExtendedPanId.m8);
scanResponse.networkNameLen = strnlen(aResult->mNetworkName.m8, OT_NETWORK_NAME_MAX_SIZE);
static_assert(OT_NETWORK_NAME_MAX_SIZE <= UINT8_MAX, "Network name length won't fit");
scanResponse.networkNameLen = static_cast<uint8_t>(strnlen(aResult->mNetworkName.m8, OT_NETWORK_NAME_MAX_SIZE));
memcpy(scanResponse.networkName, aResult->mNetworkName.m8, scanResponse.networkNameLen);

mScanResponseIter.Add(&scanResponse);
Expand Down Expand Up @@ -1168,7 +1169,7 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::_WriteThreadNetw
}
else
{
lastRssi.SetNonNull(((neighInfo.mLastRssi > 0) ? 0 : neighInfo.mLastRssi));
lastRssi.SetNonNull(min(static_cast<int8_t>(0), neighInfo.mLastRssi));
}

neighborTable.averageRssi = averageRssi;
Expand Down
2 changes: 2 additions & 0 deletions src/platform/Zephyr/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,6 @@ static_library("Zephyr") {
if (chip_malloc_sys_heap) {
sources += [ "SysHeapMalloc.cpp" ]
}

cflags = [ "-Wconversion" ]
}
2 changes: 1 addition & 1 deletion src/platform/Zephyr/DiagnosticDataProviderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetTotalOperationalHours(uint32_t & total

ReturnErrorOnFailure(ConfigurationMgr().GetTotalOperationalHours(reinterpret_cast<uint32_t &>(totalHours)));

totalOperationalHours = totalHours + deltaTime < UINT32_MAX ? totalHours + deltaTime : UINT32_MAX;
totalOperationalHours = static_cast<uint32_t>(totalHours + deltaTime < UINT32_MAX ? totalHours + deltaTime : UINT32_MAX);

return CHIP_NO_ERROR;
}
Expand Down
16 changes: 13 additions & 3 deletions src/platform/Zephyr/PlatformManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include <platform/internal/CHIPDeviceLayerInternal.h>

#include <lib/support/SafeInt.h>
#include <lib/support/logging/CHIPLogging.h>
#include <platform/PlatformManager.h>
#include <platform/Zephyr/DiagnosticDataProviderImpl.h>
Expand All @@ -48,11 +49,20 @@ static k_timer sOperationalHoursSavingTimer;
static int app_entropy_source(void * data, unsigned char * output, size_t len, size_t * olen)
{
const struct device * entropy = DEVICE_DT_GET(DT_CHOSEN(zephyr_entropy));
int ret = entropy_get_entropy(entropy, output, len);
uint16_t clampedLen;
if (CanCastTo<uint16_t>(len))
{
clampedLen = static_cast<uint16_t>(len);
}
else
{
clampedLen = UINT16_MAX;
}
int ret = entropy_get_entropy(entropy, output, clampedLen);

if (ret == 0)
{
*olen = len;
*olen = clampedLen;
}
else
{
Expand Down Expand Up @@ -85,7 +95,7 @@ void PlatformManagerImpl::UpdateOperationalHours(intptr_t arg)
if (ConfigurationMgr().GetTotalOperationalHours(reinterpret_cast<uint32_t &>(totalOperationalHours)) == CHIP_NO_ERROR)
{
ConfigurationMgr().StoreTotalOperationalHours(
totalOperationalHours + deltaTime < UINT32_MAX ? totalOperationalHours + deltaTime : UINT32_MAX);
static_cast<uint32_t>(totalOperationalHours + deltaTime < UINT32_MAX ? totalOperationalHours + deltaTime : UINT32_MAX));
sInstance.mSavedOperationalHoursSinceBoot = upTimeH;
}
else
Expand Down
2 changes: 2 additions & 0 deletions src/platform/nrfconnect/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,6 @@ static_library("nrfconnect") {
if (chip_malloc_sys_heap) {
sources += [ "../Zephyr/SysHeapMalloc.cpp" ]
}

cflags = [ "-Wconversion" ]
}
12 changes: 10 additions & 2 deletions src/platform/nrfconnect/OTAImageProcessorImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,16 @@ CHIP_ERROR OTAImageProcessorImpl::ProcessBlock(ByteSpan & aBlock)
if (error == CHIP_NO_ERROR)
{
// DFU target library buffers data internally, so do not clone the block data.
error = System::MapErrorZephyr(dfu_multi_image_write(mParams.downloadedBytes, aBlock.data(), aBlock.size()));
mParams.downloadedBytes += aBlock.size();
if (mParams.downloadedBytes > std::numeric_limits<size_t>::max())
{
error = CHIP_ERROR_BUFFER_TOO_SMALL;
}
else
{
error = System::MapErrorZephyr(
dfu_multi_image_write(static_cast<size_t>(mParams.downloadedBytes), aBlock.data(), aBlock.size()));
mParams.downloadedBytes += aBlock.size();
}
}

// Report the result back to the downloader asynchronously.
Expand Down
2 changes: 1 addition & 1 deletion src/platform/nrfconnect/wifi/NrfWiFiDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ bool NrfWiFiDriver::WiFiNetworkIterator::Next(Network & item)
}

memcpy(item.networkID, mDriver->mStagingNetwork.ssid, mDriver->mStagingNetwork.ssidLen);
item.networkIDLen = mDriver->mStagingNetwork.ssidLen;
item.networkIDLen = static_cast<uint8_t>(mDriver->mStagingNetwork.ssidLen);
item.connected = false;

mExhausted = true;
Expand Down
8 changes: 4 additions & 4 deletions src/platform/nrfconnect/wifi/WiFiManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ CHIP_ERROR WiFiManager::GetWiFiInfo(WiFiInfo & info) const
info.mBssId = ByteSpan(mac_string_buf, sizeof(mac_string_buf));
info.mSecurityType = static_cast<uint8_t>(status.security);
info.mWiFiVersion = static_cast<uint8_t>(status.link_mode);
info.mRssi = status.rssi;
info.mChannel = status.channel;
info.mRssi = static_cast<int8_t>(status.rssi);
info.mChannel = static_cast<uint16_t>(status.channel);
info.mSsidLen = status.ssid_len;
memcpy(info.mSsid, status.ssid, status.ssid_len);

Expand Down Expand Up @@ -291,12 +291,12 @@ void WiFiManager::ScanResultHandler(uint8_t * data)
if (scanResult->rssi > Instance().mWiFiParams.mRssi)
{
Instance().ClearStationProvisioningData();
Instance().mWiFiParams.mParams.ssid_length = Instance().mWantedNetwork.ssidLen;
Instance().mWiFiParams.mParams.ssid_length = static_cast<uint8_t>(Instance().mWantedNetwork.ssidLen);
Instance().mWiFiParams.mParams.ssid = Instance().mWantedNetwork.ssid;
// Fallback to the WIFI_SECURITY_TYPE_PSK if the security is unknown
Instance().mWiFiParams.mParams.security =
scanResult->security <= WIFI_SECURITY_TYPE_MAX ? scanResult->security : WIFI_SECURITY_TYPE_PSK;
Instance().mWiFiParams.mParams.psk_length = Instance().mWantedNetwork.passLen;
Instance().mWiFiParams.mParams.psk_length = static_cast<uint8_t>(Instance().mWantedNetwork.passLen);

// If the security is none, WiFi driver expects the psk to be nullptr
if (Instance().mWiFiParams.mParams.security == WIFI_SECURITY_TYPE_NONE)
Expand Down