diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2005-04-17 13:09:06 +0000 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2005-04-17 13:09:06 +0000 |
commit | 607eee46b4e197ef0b3e73359b89daa0a8705516 (patch) | |
tree | e01b55c793efce1712d00ce77ee7e13bd4393070 | |
parent | 2b77e2e8198e16cae6d1411c4ec65bf87d6c4dd7 (diff) |
Fix buffer allocation for features to string conversion
-rw-r--r-- | src/hci.c | 20 |
1 files changed, 15 insertions, 5 deletions
@@ -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) { |