Skip to content

Commit 0ccf0f2

Browse files
committed
main/parse_cuda_device: validate
Validate the number, eg. `--cuda-device list` (instead of "help") now triggers error.
1 parent 403a751 commit 0ccf0f2

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/main.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,11 +401,16 @@ static int parse_cuda_device(char *optarg) {
401401
LOG(LOG_LEVEL_ERROR) << "Maximal number of CUDA device exceeded.\n";
402402
return -EXIT_FAILURE;
403403
}
404-
cuda_devices[i] = atoi(item);
404+
const int val = parse_number(optarg, 0, 16);
405+
if (val == INT_MIN) {
406+
return -EXIT_FAIL_USAGE;
407+
}
408+
cuda_devices[i] = val;
405409
optarg = NULL;
406410
++i;
407411
}
408412
cuda_devices_count = i;
413+
assert(cuda_devices_count >= 1);
409414
cuda_devices_explicit = true;
410415
return 0;
411416
}

0 commit comments

Comments
 (0)