Skip to content

Commit cdbefe9

Browse files
dedekindlenb
authored andcommitted
tools/power turbostat: Fix delimiter bug in print functions
Commands that add counters, such as 'turbostat --show C1,C1+' display merged columns without a delimiter. This is caused by the bad syntax: '(*printed++ ? delim : "")', shared by print_name()/print_hex_value()/print_decimal_value()/print_float_value() Use '((*printed)++ ? delim : "")' to correctly increment the value at *printed. [lenb: fix code and commit message typo, re-word] Fixes: 56dbb87 ("tools/power turbostat: Refactor added column header printing") Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> Signed-off-by: Len Brown <len.brown@intel.com>
1 parent b6398bc commit cdbefe9

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

tools/power/x86/turbostat/turbostat.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2837,29 +2837,29 @@ static inline int print_name(int width, int *printed, char *delim, char *name, e
28372837
UNUSED(type);
28382838

28392839
if (format == FORMAT_RAW && width >= 64)
2840-
return (sprintf(outp, "%s%-8s", (*printed++ ? delim : ""), name));
2840+
return (sprintf(outp, "%s%-8s", ((*printed)++ ? delim : ""), name));
28412841
else
2842-
return (sprintf(outp, "%s%s", (*printed++ ? delim : ""), name));
2842+
return (sprintf(outp, "%s%s", ((*printed)++ ? delim : ""), name));
28432843
}
28442844

28452845
static inline int print_hex_value(int width, int *printed, char *delim, unsigned long long value)
28462846
{
28472847
if (width <= 32)
2848-
return (sprintf(outp, "%s%08x", (*printed++ ? delim : ""), (unsigned int)value));
2848+
return (sprintf(outp, "%s%08x", ((*printed)++ ? delim : ""), (unsigned int)value));
28492849
else
2850-
return (sprintf(outp, "%s%016llx", (*printed++ ? delim : ""), value));
2850+
return (sprintf(outp, "%s%016llx", ((*printed)++ ? delim : ""), value));
28512851
}
28522852

28532853
static inline int print_decimal_value(int width, int *printed, char *delim, unsigned long long value)
28542854
{
28552855
UNUSED(width);
28562856

2857-
return (sprintf(outp, "%s%lld", (*printed++ ? delim : ""), value));
2857+
return (sprintf(outp, "%s%lld", ((*printed)++ ? delim : ""), value));
28582858
}
28592859

28602860
static inline int print_float_value(int *printed, char *delim, double value)
28612861
{
2862-
return (sprintf(outp, "%s%0.2f", (*printed++ ? delim : ""), value));
2862+
return (sprintf(outp, "%s%0.2f", ((*printed)++ ? delim : ""), value));
28632863
}
28642864

28652865
void print_header(char *delim)

0 commit comments

Comments
 (0)