Reset errno to 0 before calling strtol and testing it in mutt_atol.
Otherwise providing LONG_MAX+1 then LONG_MAX gave an error for LONG_MAX too.
* Detect overflow on negative numbers too (< LONG_MIN).
* Distinguish between format error and number overflow as already
expected (e.g. for pgp_timeout and smime_timeout).
* @param[out] dst Store the result
* @retval 0 Success
* @retval -1 Error
+ * @retval -2 Overflow
*
* This is a strtol() wrapper with range checking.
* errno may be set on error, e.g. ERANGE
return 0;
}
+ errno = 0;
*res = strtol(str, &e, 10);
- if (((*res == LONG_MAX) && (errno == ERANGE)) || (e && (*e != '\0')))
+ if (e && (*e != '\0'))
return -1;
+ if (errno == ERANGE)
+ return -2;
return 0;
}