tools/x86_energy_perf_policy: Fix comparing int with LONG_MIN and LONG_MAX
PATCH 1/1 tools/x86_energy_perf_policy: Fix comparing int with LONG_MIN and LONG_MAX
A condition that will never be met.
strtol return long value but we have int variable and strtool can overflow it.
Remove meaningless extra overflow comparisons.
Warning:
x86_energy_perf_policy.c:337:25:
warning: result of comparison of constant 9223372036854775807 with expression of type 'int' is always false
if (i == LONG_MIN || i == LONG_MAX)
~ ^ ~~~~~~~~
x86_energy_perf_policy.c:337:8:
warning: result of comparison of constant -9223372036854775808
with expression of type 'int' is always false
if (i == LONG_MIN || i == LONG_MAX)Signed-off-by Grigory Vasilyev <[email protected]>
--- .../x86_energy_perf_policy/x86_energy_perf_policy.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c +4 -8
@@ -308,7 +308,7 @@ int parse_cmdline_turbo(int i)int parse_optarg_string (char *s) { -int i; +long i;char *endptr;if (!strncmp (s,"default" ,7 ))
@@ -334,15 +334,11 @@ int parse_optarg_string(char *s)fprintf (stderr,"no digits in \"%s\"\n" , s);usage (); } -if (i ==LONG_MIN || i ==LONG_MAX ) -errx (-1 ,"%s" , s); -if (i >0xFF ) -errx (-1 ,"%d (0x%x) must be < 256" , i, i); +if (i <0 || i >255 ) +errx (-1 ,"%ld (0x%lx) must be >= 0 and < 256" , i, i); -if (i <0 ) -errx (-1 ,"%d (0x%x) must be >= 0" , i, i); -return i; +return (int )i; }void parse_cmdline_all (char *s)
Signature · 1 line
2.35.2