Skip to content

Commit

Permalink
Enable -Wconversion in src/platform/Darwin. (#25323)
Browse files Browse the repository at this point in the history
Also fixes incorrect handling of the bssid from CWNetwork.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Apr 5, 2023
1 parent 6d98917 commit 2371673
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/app/EventLoggingTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ static_assert(sizeof(std::underlying_type_t<PriorityLevel>) <= sizeof(unsigned),
*/
struct Timestamp
{
enum class Type
enum class Type : uint8_t
{
kSystem = 0,
kEpoch
Expand Down
3 changes: 2 additions & 1 deletion src/app/util/af-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

#include <app/ConcreteAttributePath.h>
#include <app/data-model/Nullable.h>
#include <lib/core/DataModelTypes.h>
#include <lib/support/Variant.h>
#include <messaging/ExchangeContext.h>

Expand Down Expand Up @@ -123,7 +124,7 @@ typedef struct
*/
typedef struct
{
uint16_t deviceId;
chip::DeviceTypeId deviceId;
uint8_t deviceVersion;
} EmberAfDeviceType;

Expand Down
10 changes: 5 additions & 5 deletions src/include/platform/BuildTime.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
// Example of __TIME__ string: "21:06:19"

#define COMPUTE_BUILD_YEAR(_date) \
(((_date)[7] - '0') * 1000 + ((_date)[8] - '0') * 100 + ((_date)[9] - '0') * 10 + ((_date)[10] - '0'))
static_cast<uint16_t>(((_date)[7] - '0') * 1000 + ((_date)[8] - '0') * 100 + ((_date)[9] - '0') * 10 + ((_date)[10] - '0'))

#define COMPUTE_BUILD_DAY(_date) ((((_date)[4] >= '0') ? ((_date)[4] - '0') * 10 : 0) + ((_date)[5] - '0'))
#define COMPUTE_BUILD_DAY(_date) static_cast<uint8_t>((((_date)[4] >= '0') ? ((_date)[4] - '0') * 10 : 0) + ((_date)[5] - '0'))

#define BUILD_MONTH_IS_JAN(_date) ((_date)[0] == 'J' && (_date)[1] == 'a')
#define BUILD_MONTH_IS_FEB(_date) ((_date)[0] == 'F')
Expand Down Expand Up @@ -63,9 +63,9 @@
? 11 \
: (BUILD_MONTH_IS_DEC(_date)) ? 12 : /* error default */ 99)

#define COMPUTE_BUILD_HOUR(_time) (((_time)[0] - '0') * 10 + (_time)[1] - '0')
#define COMPUTE_BUILD_MIN(_time) (((_time)[3] - '0') * 10 + (_time)[4] - '0')
#define COMPUTE_BUILD_SEC(_time) (((_time)[6] - '0') * 10 + (_time)[7] - '0')
#define COMPUTE_BUILD_HOUR(_time) static_cast<uint8_t>(((_time)[0] - '0') * 10 + (_time)[1] - '0')
#define COMPUTE_BUILD_MIN(_time) static_cast<uint8_t>(((_time)[3] - '0') * 10 + (_time)[4] - '0')
#define COMPUTE_BUILD_SEC(_time) static_cast<uint8_t>(((_time)[6] - '0') * 10 + (_time)[7] - '0')

#define BUILD_DATE_IS_BAD(_date) ((_date) == nullptr || strlen(_date) < strlen("Jan 01 2000") || (_date)[0] == '?')
#define BUILD_TIME_IS_BAD(_time) ((_time) == nullptr || strlen(_time) < strlen("00:00:00") || (_time)[0] == '?')
2 changes: 1 addition & 1 deletion src/messaging/tests/echo/echo_requester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ void HandleEchoResponseReceived(chip::Messaging::ExchangeContext * ec, chip::Sys
gEchoRespCount++;

printf("Echo Response: %" PRIu64 "/%" PRIu64 "(%.2f%%) len=%u time=%.3fs\n", gEchoRespCount, gEchoCount,
static_cast<double>(gEchoRespCount) * 100 / gEchoCount, payload->DataLength(),
static_cast<double>(gEchoRespCount) * 100 / static_cast<double>(gEchoCount), payload->DataLength(),
static_cast<double>(chip::System::Clock::Milliseconds32(transitTime).count()) / 1000);
}

Expand Down
10 changes: 8 additions & 2 deletions src/platform/Darwin/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ config("darwin_config") {
]
}

cflags = [ "-fobjc-arc" ]
cflags = [
"-fobjc-arc",
"-Wconversion",
]
}

static_library("Darwin") {
Expand Down Expand Up @@ -140,6 +143,9 @@ static_library("logging") {
]

configs += [ "${chip_root}/src:includes" ]
cflags = [ "-fobjc-arc" ]
cflags = [
"-fobjc-arc",
"-Wconversion",
]
frameworks = [ "Foundation.framework" ]
}
3 changes: 2 additions & 1 deletion src/platform/Darwin/BleConnectionDelegateImpl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ - (void)resetTimer
{
auto timeout =
[self hasDiscriminator] ? kScanningWithDiscriminatorTimeoutInSeconds : kScanningWithoutDiscriminatorTimeoutInSeconds;
dispatch_source_set_timer(_timer, dispatch_walltime(nullptr, timeout * NSEC_PER_SEC), DISPATCH_TIME_FOREVER, 5 * NSEC_PER_SEC);
dispatch_source_set_timer(
_timer, dispatch_walltime(nullptr, static_cast<int64_t>(timeout * NSEC_PER_SEC)), DISPATCH_TIME_FOREVER, 5 * NSEC_PER_SEC);
}

// All our callback dispatch must happen on _chipWorkQueue
Expand Down
7 changes: 6 additions & 1 deletion src/platform/Darwin/ConnectivityManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <new>

#include <lib/support/CodeUtils.h>
#include <lib/support/SafeInt.h>
#include <lib/support/logging/CHIPLogging.h>

#include <platform/internal/GenericConnectivityManagerImpl_UDP.ipp>
Expand Down Expand Up @@ -80,6 +81,10 @@ CHIP_ERROR ConnectivityManagerImpl::GetEthernetInterfaceName(char * outName, siz
{
CHIP_ERROR err = CHIP_ERROR_NOT_IMPLEMENTED;
#if TARGET_OS_OSX
if (!CanCastTo<CFIndex>(maxLen))
{
return CHIP_ERROR_INVALID_ARGUMENT;
}
CFArrayRef interfaces = SCNetworkInterfaceCopyAll();
VerifyOrReturnError(interfaces != nullptr, CHIP_ERROR_INTERNAL);

Expand All @@ -102,7 +107,7 @@ CHIP_ERROR ConnectivityManagerImpl::GetEthernetInterfaceName(char * outName, siz
continue;
}

if (!CFStringGetCString(interfaceName, outName, maxLen, kCFStringEncodingUTF8))
if (!CFStringGetCString(interfaceName, outName, static_cast<CFIndex>(maxLen), kCFStringEncodingUTF8))
{
continue;
}
Expand Down
3 changes: 2 additions & 1 deletion src/platform/Darwin/DnssdHostNameRegistrar.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ namespace Dnssd {
auto interfaceAddress = static_cast<const void *>(&interface.second);
auto interfaceAddressLen = sizeof(interface.second);

LogErrorOnFailure(RegisterInterface(interfaceId, type, interfaceAddress, interfaceAddressLen));
LogErrorOnFailure(
RegisterInterface(interfaceId, type, interfaceAddress, static_cast<uint16_t>(interfaceAddressLen)));
}
}

Expand Down
28 changes: 17 additions & 11 deletions src/platform/Darwin/WiFi/NetworkCommissioningWiFiDriver.mm
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* limitations under the License.
*/

#include <lib/support/BytesToHex.h>
#include <lib/support/CodeUtils.h>
#include <platform/CHIPDeviceLayer.h>
#include <platform/Darwin/ConfigurationManagerImpl.h>
Expand Down Expand Up @@ -72,18 +73,23 @@ bool Next(WiFiScanResponse & scanResponse) override
void CopyNetworkInformationTo(WiFiScanResponse & destination, CWNetwork * source)
{
destination.security = GetWiFiSecurity(source);
destination.ssidLen = [source.ssid length];
destination.channel = source.wlanChannel.channelNumber;
destination.channel = static_cast<uint16_t>(source.wlanChannel.channelNumber);
destination.wiFiBand = GetWiFiBand(source.wlanChannel);
destination.rssi = source.rssiValue;
CopyStringTo(destination.ssid, source.ssid, DeviceLayer::Internal::kMaxWiFiSSIDLength);
CopyStringTo(destination.bssid, source.bssid, DeviceLayer::Internal::kWiFiBSSIDLength);
}

void CopyStringTo(uint8_t * destination, NSString * source, size_t maxLength)
{
NSData * data = [source dataUsingEncoding:NSUTF8StringEncoding];
memcpy(destination, [data bytes], std::min([data length], maxLength));
destination.rssi = static_cast<int8_t>(source.rssiValue);

NSData * ssidData = source.ssidData;
destination.ssidLen = static_cast<uint8_t>(std::min(ssidData.length, DeviceLayer::Internal::kMaxWiFiSSIDLength));
memcpy(destination.ssid, ssidData.bytes, destination.ssidLen);

// source.bssid looks like "00:00:00:00:00:00" if it's not nil.
NSString * bssid = source.bssid;
// 3 chars per byte, except the last byte.
if (bssid.length == 3 * sizeof(destination.bssid) - 1) {
const char * chars = bssid.UTF8String;
for (size_t i = 0; i < sizeof(destination.bssid); ++i) {
Encoding::HexToBytes(&chars[3 * i], 2, &destination.bssid[i], 1);
}
}
}

WiFiSecurity GetWiFiSecurity(CWNetwork * network)
Expand Down

0 comments on commit 2371673

Please sign in to comment.