]> granicus.if.org Git - esp-idf/commitdiff
component/bt: Fix bug: string_to_bdaddr() error when opening nano
authorbaohongde <baohongde@espressif.com>
Mon, 26 Feb 2018 07:09:03 +0000 (15:09 +0800)
committerbaohongde <baohongde@espressif.com>
Mon, 26 Feb 2018 07:09:03 +0000 (15:09 +0800)
components/bt/bluedroid/btcore/bdaddr.c

index e69bb53e1f162b653c8865410e84bbf7bb96779e..e2466fa6bb1b01bb62c192133535efa59dd937fa 100644 (file)
@@ -102,10 +102,13 @@ bool string_to_bdaddr(const char *string, bt_bdaddr_t *addr)
 
     bt_bdaddr_t new_addr;
     uint8_t *ptr = new_addr.address;
-    bool ret = sscanf(string, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
-                      &ptr[0], &ptr[1], &ptr[2], &ptr[3], &ptr[4], &ptr[5]) == 6;
-
+    uint32_t ptr_32[6];
+    bool ret  = sscanf(string, "%02x:%02x:%02x:%02x:%02x:%02x",
+                      &ptr_32[0], &ptr_32[1], &ptr_32[2], &ptr_32[3], &ptr_32[4], &ptr_32[5]) == 6;
     if (ret) {
+        for (uint8_t i = 0; i < 6; i++){
+            ptr[i] = (uint8_t) ptr_32[i];
+        }
         memcpy(addr, &new_addr, sizeof(bt_bdaddr_t));
     }