Skip to content

Commit 0cb1a7d

Browse files
brosahayrosahay-silabs
authored andcommitted
Simplify SSID processing and improve memory handling
1 parent 64cbfa6 commit 0cb1a7d

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

examples/platform/silabs/efr32/rs911x/rsi_if.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -751,17 +751,16 @@ void ProcessEvent(WfxEvent_t inEvent)
751751
scan = &scan_rsp.scan_info[x];
752752
// clear structure and calculate size of SSID
753753
memset(&ap, 0, sizeof(ap));
754-
ap.ssid_length = strnlen((char *) scan->ssid, chip::min<size_t>(sizeof(scan->ssid), WFX_MAX_SSID_LENGTH));
755-
strncpy(ap.ssid, (char *) scan->ssid, ap.ssid_length);
756-
// assure null termination of scanned SSID
757-
ap.ssid[ap.ssid_length - 1] = 0;
754+
ap.ssid_length =
755+
strnlen(reinterpret_cast<char *>(scan->ssid), chip::min<size_t>(sizeof(scan->ssid), WFX_MAX_SSID_LENGTH));
756+
chip::Platform::CopyString(ap.ssid, ap.ssid_length, reinterpret_cast<char *>(scan->ssid));
758757

759758
// check if the scanned ssid is the one we are looking for
760-
if (wfx_rsi.scan_ssid_length != 0 && strcmp(wfx_rsi.scan_ssid, ap.ssid) != CMP_SUCCESS)
759+
if (wfx_rsi.scan_ssid_length != 0 && strncmp(wfx_rsi.scan_ssid, ap.ssid, WFX_MAX_SSID_LENGTH) != CMP_SUCCESS)
761760
{
762761
continue; // we found the targeted ssid.
763762
}
764-
// TODO: Add support to convert security mode from RSI to WFX
763+
// TODO: convert security mode from RSI to WFX
765764
ap.security = static_cast<wfx_sec_t>(scan->security_mode);
766765
ap.rssi = (-1) * scan->rssi_val;
767766

examples/platform/silabs/efr32/wf200/host_if.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1174,7 +1174,7 @@ bool wfx_start_scan(char * ssid, void (*callback)(wfx_wifi_scan_result_t *))
11741174
VerifyOrReturnError(scan_cb != nullptr, false);
11751175
if (ssid)
11761176
{
1177-
scan_ssid_length = strnlen(ssid, chip::min<size_t>(sizeof(ssid), WFX_MAX_SSID_LENGTH));
1177+
scan_ssid_length = strnlen(ssid, WFX_MAX_SSID_LENGTH);
11781178
scan_ssid = reinterpret_cast<char *>(chip::Platform::MemoryAlloc(scan_ssid_length));
11791179
VerifyOrReturnError(scan_ssid != nullptr, false);
11801180
Platform::CopyString(scan_ssid, scan_ssid_length, ssid);

0 commit comments

Comments
 (0)