monitor: RTNL IFLA flags were printed incorrectly

If flags was 0, then an uninitialized buffer was printed. Changed
this so that if flags == 0, then just the value is printed.
If flags != 0, then print flags values to a buffer that is big
enough to hold all the sub-strings.
This commit is contained in:
Jukka Rissanen 2015-02-25 15:41:59 +02:00 committed by Denis Kenzior
parent e69b21ccdf
commit 7a16f0a263
1 changed files with 6 additions and 7 deletions

View File

@ -2621,27 +2621,26 @@ static void ififlags_str(char *str, size_t size, uint16_t flags)
{
int pos, i;
if (!str || !flags)
pos = sprintf(str, "(0x%02x)", flags);
if (!flags)
return;
pos = sprintf(str, "(0x%02x)", flags);
pos += sprintf(str + pos, " [");
for (i = 0; rtnl_flags[i].name; i++) {
if (flags & rtnl_flags[i].flag) {
flags &= ~rtnl_flags[i].flag;
pos += sprintf(str + pos, "%s%c", rtnl_flags[i].name,
flags ? ',' : ']');
pos += sprintf(str + pos, "%s%s", rtnl_flags[i].name,
flags ? "," : "");
}
}
if (flags)
pos += sprintf(str + pos, "0x%x]", flags);
pos += sprintf(str + pos, "]");
}
static void print_ifinfomsg(const struct ifinfomsg *info)
{
char str[64];
char str[256];
if (!info)
return;