revisit some calls of strtol(), stroul(), strtoull()

Replace some with atoi(), where the VTY has already validated correct
range of the argument.

Replace others with the new osmo_str_to_int() or osmo_str_to_int64()
functions, possibly covering more detection of invalid number strings.

Leave those strtol() callers that depend on endptr to provide the next
string token.

Related: SYS#5542
Change-Id: I0ebb06e751c28f7d1cdf328de29cd227a2449391
diff --git a/src/vty/command.c b/src/vty/command.c
index e5e7d15..2a8942d 100644
--- a/src/vty/command.c
+++ b/src/vty/command.c
@@ -1349,7 +1349,6 @@
 	int colons = 0, nums = 0, double_colon = 0;
 	int mask;
 	const char *sp = NULL;
-	char *endptr = NULL;
 
 	if (str == NULL)
 		return PARTLY_MATCH;
@@ -1447,11 +1446,7 @@
 	if (state < STATE_MASK)
 		return PARTLY_MATCH;
 
-	mask = strtol(str, &endptr, 10);
-	if (*endptr != '\0')
-		return NO_MATCH;
-
-	if (mask < 0 || mask > 128)
+	if (osmo_str_to_int(&mask, str, 10, 0, 128))
 		return NO_MATCH;
 
 /* I don't know why mask < 13 makes command match partly.
@@ -3794,16 +3789,7 @@
       "Set number of lines on a screen\n"
       "Number of lines on screen (0 for no pausing)\n")
 {
-	int lines;
-	char *endptr = NULL;
-
-	lines = strtol(argv[0], &endptr, 10);
-	if (lines < 0 || lines > 512 || *endptr != '\0') {
-		vty_out(vty, "length is malformed%s", VTY_NEWLINE);
-		return CMD_WARNING;
-	}
-	vty->lines = lines;
-
+	vty->lines = atoi(argv[0]);
 	return CMD_SUCCESS;
 }
 
@@ -3822,16 +3808,7 @@
       "System wide terminal length configuration\n"
       "Number of lines of VTY (0 means no line control)\n")
 {
-	int lines;
-	char *endptr = NULL;
-
-	lines = strtol(argv[0], &endptr, 10);
-	if (lines < 0 || lines > 512 || *endptr != '\0') {
-		vty_out(vty, "length is malformed%s", VTY_NEWLINE);
-		return CMD_WARNING;
-	}
-	host.lines = lines;
-
+	host.lines = atoi(argv[0]);
 	return CMD_SUCCESS;
 }
 
diff --git a/src/vty/cpu_sched_vty.c b/src/vty/cpu_sched_vty.c
index 4ccc627..0b4b249 100644
--- a/src/vty/cpu_sched_vty.c
+++ b/src/vty/cpu_sched_vty.c
@@ -276,7 +276,6 @@
 static enum sched_vty_thread_id procname2pid(pid_t *res_pid, const char *str, bool applynow)
 {
 	size_t i, len;
-	char *end;
 	bool is_pid = true;
 
 	if (strcmp(str, "all") == 0) {
@@ -297,12 +296,12 @@
 		}
 	}
 	if (is_pid) {
-		errno = 0;
-		*res_pid = strtoul(str, &end, 0);
-		if ((errno == ERANGE && *res_pid == ULONG_MAX) || (errno && !*res_pid) ||
-		    str == end) {
+		int64_t val;
+		if (osmo_str_to_int64(&val, str, 0, 0, INT64_MAX))
 			return SCHED_VTY_THREAD_UNKNOWN;
-		}
+		*res_pid = (pid_t)val;
+		if (*res_pid != val)
+			return SCHED_VTY_THREAD_UNKNOWN;
 		if (!applynow || proc_tid_exists(*res_pid))
 			return SCHED_VTY_THREAD_ID;
 		else
diff --git a/src/vty/tdef_vty.c b/src/vty/tdef_vty.c
index 0556d8c..09459f1 100644
--- a/src/vty/tdef_vty.c
+++ b/src/vty/tdef_vty.c
@@ -50,10 +50,9 @@
  */
 struct osmo_tdef *osmo_tdef_vty_parse_T_arg(struct vty *vty, struct osmo_tdef *tdefs, const char *T_str)
 {
-	long l;
+	int l;
 	int T;
 	struct osmo_tdef *t;
-	char *endptr;
 	const char *T_nr_str;
 	int sign = 1;
 
@@ -77,9 +76,7 @@
 		return NULL;
 	}
 
-	errno = 0;
-	l = strtol(T_nr_str, &endptr, 10);
-	if (errno || *endptr || l > INT_MAX || l < 0) {
+	if (osmo_str_to_int(&l, T_nr_str, 10, 0, INT_MAX)) {
 		vty_out(vty, "%% Invalid T timer argument (should be 'T1234' or 'X1234'): '%s'%s", T_str, VTY_NEWLINE);
 		return NULL;
 	}