You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2017/05/18 23:59:15 UTC

[3/9] incubator-mynewt-core git commit: MYNEWT-754 BLE host - addrcmp ignores padding.

MYNEWT-754 BLE host - addrcmp ignores padding.

A straight memcmp of the ble_addr_t struct won't always work,
particularly if one of the structs is allocated on the stack.  The
contents of the padding bytes are indeterminate, and could cause a false
negative.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/02f60846
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/02f60846
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/02f60846

Branch: refs/heads/master
Commit: 02f60846684b0f51dbfe050795b144e0f8b35641
Parents: f0a1ea8
Author: Christopher Collins <cc...@apache.org>
Authored: Thu May 11 14:39:23 2017 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Thu May 11 18:00:22 2017 -0700

----------------------------------------------------------------------
 net/nimble/include/nimble/ble.h | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/02f60846/net/nimble/include/nimble/ble.h
----------------------------------------------------------------------
diff --git a/net/nimble/include/nimble/ble.h b/net/nimble/include/nimble/ble.h
index 6f29fd4..f0c2d23 100644
--- a/net/nimble/include/nimble/ble.h
+++ b/net/nimble/include/nimble/ble.h
@@ -235,7 +235,14 @@ typedef struct {
 
 static inline int ble_addr_cmp(const ble_addr_t *a, const ble_addr_t *b)
 {
-    return memcmp(a, b, sizeof(*a));
+    int type_diff;
+
+    type_diff = a->type - b->type;
+    if (type_diff != 0) {
+        return type_diff;
+    }
+
+    return memcmp(a->val, b->val, sizeof(a->val));
 }
 
 #ifdef __cplusplus