summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2005-04-17 13:09:06 +0000
committerMarcel Holtmann <marcel@holtmann.org>2005-04-17 13:09:06 +0000
commit607eee46b4e197ef0b3e73359b89daa0a8705516 (patch)
treee01b55c793efce1712d00ce77ee7e13bd4393070 /src
parent2b77e2e8198e16cae6d1411c4ec65bf87d6c4dd7 (diff)
Fix buffer allocation for features to string conversion
Diffstat (limited to 'src')
-rw-r--r--src/hci.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/hci.c b/src/hci.c
index a0c0775e..ddcd680b 100644
--- a/src/hci.c
+++ b/src/hci.c
@@ -414,9 +414,20 @@ static hci_map lmp_features_map[8][9] = {
char *lmp_featurestostr(uint8_t *features, char *pref, int width)
{
- char *off, *ptr, *str = malloc(400);
- int i;
+ char *off, *ptr, *str;
+ int i, size = 0;
+ for (i = 0; i < 8; i++) {
+ hci_map *m = lmp_features_map[i];
+
+ while (m->str) {
+ if ((unsigned int) m->val & (unsigned int) features[i])
+ size += strlen(m->str) + (pref ? strlen(pref) : 0) + 1;
+ m++;
+ }
+ }
+
+ str = malloc(size);
if (!str)
return NULL;
@@ -427,10 +438,9 @@ char *lmp_featurestostr(uint8_t *features, char *pref, int width)
off = ptr;
- for (i = 0; i < 8; i++) {
- hci_map *m;
+ for (i = 0; i < 8; i++) {
+ hci_map *m = lmp_features_map[i];
- m = lmp_features_map[i];
while (m->str) {
if ((unsigned int) m->val & (unsigned int) features[i]) {
if (strlen(off) + strlen(m->str) > width - 1) {