monitor: Fix p2p channel list dumper

This dumper probably intended to update pos after invoking strncpy.
However, strncpy returns the number of bytes that *would* have been
copied and so the logic gets a bit complex to get completely right.

Instead, switch to using l_string since this is inside the monitor and
not particularly performance critical.
This commit is contained in:
Denis Kenzior 2019-10-17 11:49:11 -05:00
parent 39bb4d07ee
commit 0b8de3d5df
1 changed files with 13 additions and 5 deletions

View File

@ -3013,8 +3013,9 @@ static void print_p2p_channel_list(unsigned int level, const char *label,
while (size) {
uint8_t channels;
char str[128];
int pos = 0;
struct l_string *string;
char *str;
bool first = true;
if (size < 2 || size < 2 + bytes[1]) {
printf("malformed P2P %s\n", label);
@ -3025,11 +3026,18 @@ static void print_p2p_channel_list(unsigned int level, const char *label,
channels = *bytes++;
size -= 2 + channels;
while (channels--)
snprintf(str + pos, sizeof(str) - pos, "%s%u",
pos ? ", " : "", (int) *bytes++);
string = l_string_new(128);
while (channels--) {
l_string_append_printf(string, "%s%u",
first ? "" : ", ",
(int ) *bytes++);
first = false;
}
str = l_string_unwrap(string);
print_attr(level + 2, "%s", str);
l_free(str);
}
}