From: Caspar Z. <ca...@ca...> - 2012-02-09 09:45:58
|
On 02/09/2012 05:30 PM, Wanlong Gao wrote: > On 02/09/2012 04:13 PM, Caspar Zhang wrote: > >> + >> +long safe_strtol(const char *file, const int lineno, >> + void (cleanup_fn)(void), char *str, long min, long max) >> +{ >> + int rval; >> + char *endptr; >> + >> + rval = strtol(str, &endptr, 10); >> + if (rval == LONG_MAX || rval == LONG_MIN) > > > Shouldn't we check the errno here? Ah yes. I'll make a v2 soon. > > Thanks > -Wanlong Gao > >> + tst_brkm(TBROK|TERRNO, cleanup_fn, "strtol failed at %s:%d", >> + file, lineno); >> + if (rval >= max || rval <= min) >> + tst_brkm(TBROK, cleanup_fn, >> + "converted value out of range: %ld - %ld", >> + min, max); >> + if (endptr == str || (*endptr != '\0' && *endptr != '\n')) >> + tst_brkm(TBROK, cleanup_fn, "Invalid value: %s", str); >> + >> + return rval; >> +} > > |