8000 Merge pull request #3036 from dhalbert/prefix-match-all · adafruit/circuitpython@0e3cad0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0e3cad0

Browse files
authored
Merge pull request #3036 from dhalbert/prefix-match-all
Fix ScanEntry prefix matching for any=False
2 parents a345223 + c91435e commit 0e3cad0

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

shared-module/_bleio/ScanEntry.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,16 @@ bool bleio_scanentry_data_matches(const uint8_t* data, size_t len, const uint8_t
5656
if (prefixes_length == 0) {
5757
return true;
5858
}
59+
if (len == 0) {
60+
// Prefixes exist, but no data.
61+
return false;
62+
}
5963
size_t i = 0;
6064
while(i < prefixes_length) {
6165
uint8_t prefix_length = prefixes[i];
6266
i += 1;
6367
size_t j = 0;
68+
bool prefix_matched = false;
6469
while (j < len) {
6570
uint8_t structure_length = data[j];
6671
j += 1;
@@ -71,13 +76,18 @@ bool bleio_scanentry_data_matches(const uint8_t* data, size_t len, const uint8_t
7176
if (any) {
7277
return true;
7378
}
74-
} else if (!any) {
75-
return false;
79+
prefix_matched = true;
80+
break;
7681
}
7782
j += structure_length;
7883
}
84+
// If all (!any), the current prefix must have matched at least one field.
85+
if (!prefix_matched && !any) {
86+
return false;
87+
}
7988
i += prefix_length;
8089
}
90+
// All prefixes matched some field (if !any), or none did (if any).
8191
return !any;
8292
}
8393

0 commit comments

Comments
 (0)
0