Archived
add safety checks
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
#include "includes/include.h"
|
||||
#include "src/driver.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int sens;
|
||||
char input[100];
|
||||
|
||||
printf("K1NG PRO (4k) driver | Cli\n");
|
||||
printf("set any sens from 50-26000\n\n");
|
||||
@@ -10,8 +14,15 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
if (argc < 2) {
|
||||
printf("set sensitivity to: ");
|
||||
if (scanf("%d", &sens) != 1) {
|
||||
printf("u forgot to input a number?\n");
|
||||
if (fgets(input, sizeof(input), stdin) == NULL || input[0] == '\n') {
|
||||
printf("incorrect input press enter to try again\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
char *endptr;
|
||||
sens = (int)strtol(input, &endptr, 10);
|
||||
if (*endptr != '\n' && *endptr != '\0') {
|
||||
printf("incorrect input press enter to try again\n");
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
@@ -19,6 +30,11 @@ int main(int argc, char *argv[]) {
|
||||
printf("set sensitivity to: %d\n", sens);
|
||||
}
|
||||
|
||||
if (sens < 50 || sens > 26000 || sens % 50 != 0) {
|
||||
printf("incorrect input press enter to try again\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
run_driver(sens);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user