summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Krasnyansky <maxk@qualcomm.com>2002-03-25 19:12:16 +0000
committerMax Krasnyansky <maxk@qualcomm.com>2002-03-25 19:12:16 +0000
commit87f8b3bc7c1967cef913de6b23bbdebb8f98d19e (patch)
treec99cdad5d76084c4ac55dd2919968bfd30cf1f48 /src
parent0a6472fe170438016c23c71d9129e627f26cd398 (diff)
Fix static allocations.
Diffstat (limited to 'src')
-rw-r--r--src/bluetooth.c45
-rw-r--r--src/hci.c34
2 files changed, 49 insertions, 30 deletions
diff --git a/src/bluetooth.c b/src/bluetooth.c
index b202f280..add25594 100644
--- a/src/bluetooth.c
+++ b/src/bluetooth.c
@@ -44,33 +44,34 @@ void baswap(bdaddr_t *dst, bdaddr_t *src)
d[i] = s[5-i];
}
-char * batostr(bdaddr_t *ba)
+char *batostr(bdaddr_t *ba)
{
- static char str[2][18];
- static int i = 1;
+ char *str = malloc(18);
+ if (!str)
+ return NULL;
- i ^= 1;
- sprintf(str[i], "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
+ sprintf(str, "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
ba->b[0], ba->b[1], ba->b[2],
ba->b[3], ba->b[4], ba->b[5]);
- return str[i];
+ return str;
}
-bdaddr_t * strtoba(char *str)
+bdaddr_t *strtoba(char *str)
{
- static unsigned char ba[2][sizeof(bdaddr_t)];
- static int i = 1;
- register char *ptr = str;
- register int x;
-
- i ^= 1;
- for(x=0; x<6; x++){
- ba[i][x] = (uint8_t) strtol(ptr, NULL, 16);
- if( x!=5 && !(ptr=strchr(ptr,':')) )
+ char *ptr = str;
+ int i;
+
+ uint8_t *ba = malloc(sizeof(bdaddr_t));
+ if (!ba)
+ return NULL;
+
+ for(i=0; i<6; i++){
+ ba[i] = (uint8_t) strtol(ptr, NULL, 16);
+ if( i!=5 && !(ptr=strchr(ptr,':')) )
ptr = ":00:00:00:00:00";
ptr++;
}
- return (bdaddr_t *) ba[i];
+ return (bdaddr_t *) ba;
}
int ba2str(bdaddr_t *ba, char *str)
@@ -82,13 +83,13 @@ int ba2str(bdaddr_t *ba, char *str)
int str2ba(char *str, bdaddr_t *ba)
{
- unsigned char *b = (void *) ba;
+ uint8_t *b = (void *) ba;
char *ptr = str;
- register int x;
+ int i;
- for (x=0; x < 6; x++) {
- b[x] = (uint8_t) strtol(ptr, NULL, 16);
- if (x!=5 && !(ptr=strchr(ptr, ':')))
+ for (i=0; i < 6; i++) {
+ b[i] = (uint8_t) strtol(ptr, NULL, 16);
+ if (i!=5 && !(ptr=strchr(ptr, ':')))
ptr = ":00:00:00:00:00";
ptr++;
}
diff --git a/src/hci.c b/src/hci.c
index 3e1dd52e..fb7a2780 100644
--- a/src/hci.c
+++ b/src/hci.c
@@ -53,9 +53,12 @@ typedef struct {
static char *hci_bit2str(hci_map *m, unsigned int val)
{
- static char str[50];
+ char *str = malloc(50);
char *ptr = str;
+ if (!str)
+ return NULL;
+
*ptr = 0;
while (m->str) {
if ((unsigned int) m->val & val)
@@ -71,10 +74,10 @@ static int hci_str2bit(hci_map *map, char *str, unsigned int *val)
hci_map *m;
int set;
+ str = ptr = strdup(str);
if (!str)
return 0;
- str = ptr = strdup(str);
*val = set = 0;
while ((t=strsep(&ptr, ","))) {
@@ -92,9 +95,12 @@ static int hci_str2bit(hci_map *map, char *str, unsigned int *val)
static char *hci_uint2str(hci_map *m, unsigned int val)
{
- static char str[50];
+ char *str = malloc(50);
char *ptr = str;
+ if (!str)
+ return NULL;
+
*ptr = 0;
while (m->str) {
if ((unsigned int) m->val == val) {
@@ -161,10 +167,13 @@ hci_map dev_flags_map[] = {
};
char *hci_dflagstostr(uint32_t flags)
{
- static char str[50];
+ char *str = malloc(50);
char *ptr = str;
hci_map *m = dev_flags_map;
+ if (!str)
+ return NULL;
+
*ptr = 0;
if (!hci_test_bit(HCI_UP, &flags))
@@ -230,13 +239,22 @@ hci_map link_mode_map[] = {
};
char *hci_lmtostr(unsigned int lm)
{
- static char str[50];
+ char *s, *str = malloc(50);
+ if (!str)
+ return NULL;
- str[0] = 0;
+ *str = 0;
if (!(lm & HCI_LM_MASTER))
strcpy(str, "SLAVE ");
- strcat(str, hci_bit2str(link_mode_map, lm));
+ s = hci_bit2str(link_mode_map, lm);
+ if (!s) {
+ free(str);
+ return NULL;
+ }
+
+ strcat(str, s);
+ free(s);
return str;
}
int hci_strtolm(char *str, unsigned int *val)
@@ -706,7 +724,7 @@ int hci_read_local_version(int dd, struct hci_version *ver, int to)
}
ver->manufacturer = btohs(rp.manufacturer);
- ver->hci_ver = rp.lmp_ver;
+ ver->hci_ver = rp.hci_ver;
ver->hci_rev = btohs(rp.hci_rev);
ver->lmp_ver = rp.lmp_ver;
ver->lmp_subver = btohs(rp.lmp_subver);