I've come to the conclusion that the problem does not lie in that code I have provided. The real problem lies in this code:
Code:
memset(name, 0, sizeof(name));
if (hci_read_remote_name(sock, &(ii+i)->bdaddr, sizeof(name), name, 0) < 0)
strcpy(name, "[unknown]");
/* Creates Next Element */
b_push_end(hb_list, name, batostr(&(ii+i)->bdaddr));
What is happening in that code, is that it is getting the name of a bluetooth device and adding it to the end of a linked list. The linked list code works fine which is b_push_end(). The function takes the list that should be added to, the name of the bluetooth devices and the mac address of the bluetooth device. What is happening is that when the name is pushed through it is just random letters keying into the idea of a memory issue. This only happens with name.
The weird part is, if I add printf(name); above b_push_end(), the actual name goes through. Here are my results without printf(name); in the code:
$~ ./program
�珿h6��0��+k D2:69:63:xx:xx:xx
End of list.
Here are my results with printf(name); in the code:
$~ ./program
MyPhone D2:69:63:xx:xx:xx
End of list.
Does anyone know what would cause this and why?
Any ideas would be appreciated.
Thanks
Brian