Commit 8e5c0cc3 authored by Kaushlendra Kumar's avatar Kaushlendra Kumar Committed by Len Brown
Browse files

tools/power turbostat: Use strtoul() for iteration parsing



Replace strtod() with strtoul() and check errno for -n/-N options, since
num_iterations and header_iterations are unsigned long counters. Reject
zero and conversion errors; negative inputs wrap to large positive values
per standard unsigned semantics.

Signed-off-by: default avatarKaushlendra Kumar <kaushlendra.kumar@intel.com>
Signed-off-by: default avatarLen Brown <len.brown@intel.com>
parent a2b4d0f8
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -11536,18 +11536,20 @@ void cmdline(int argc, char **argv)
			/* Parsed earlier */
			break;
		case 'n':
			num_iterations = strtod(optarg, NULL);
			num_iterations = strtoul(optarg, NULL, 0);
			errno = 0;

			if (num_iterations <= 0) {
				fprintf(outf, "iterations %d should be positive number\n", num_iterations);
			if (errno || num_iterations == 0) {
				fprintf(outf, "invalid iteration count: %s\n", optarg);
				exit(2);
			}
			break;
		case 'N':
			header_iterations = strtod(optarg, NULL);
			header_iterations = strtoul(optarg, NULL, 0);
			errno = 0;

			if (header_iterations <= 0) {
				fprintf(outf, "iterations %d should be positive number\n", header_iterations);
			if (errno || header_iterations == 0) {
				fprintf(outf, "invalid header iteration count: %s\n", optarg);
				exit(2);
			}
			break;