+2002-06-04 Ken Raeburn <raeburn@mit.edu>
+
+ * prof_get.c (profile_get_integer): Set errno to 0 before strtol
+ call, so we can distinguish error from LONG_MIN/MAX. Break out
+ different error conditions and comment them.
+
2002-05-08 Ken Raeburn <raeburn@mit.edu>
* prof_get.c (conf_yes, conf_no): Now const.
char *end_value;
long ret_long;
- if (profile == 0) {
- *ret_int = def_val;
+ *ret_int = def_val;
+ if (profile == 0)
return 0;
- }
names[0] = name;
names[1] = subname;
return 0;
} else if (retval)
return retval;
-
+
+ if (value[0] == 0)
+ /* Empty string is no good. */
+ return PROF_BAD_INTEGER;
+ errno = 0;
ret_long = strtol (value, &end_value, 10);
- if ((errno != 0) || (end_value != value + strlen (value)) ||
- (end_value == value) || (ret_long > INT_MAX) ||
- (ret_long < INT_MIN)) {
+
+ /* Overflow or underflow. */
+ if ((ret_long == LONG_MIN || ret_long == LONG_MAX) && errno != 0)
+ return PROF_BAD_INTEGER;
+ /* Value outside "int" range. */
+ if ((long) (int) ret_long != ret_long)
+ return PROF_BAD_INTEGER;
+ /* Garbage in string. */
+ if (end_value != value + strlen (value))
return PROF_BAD_INTEGER;
- }
*ret_int = ret_long;