@@ -614,16 +614,16 @@ unsigned long safe_strtoul(const char *file, const int lineno,
return rval;
}
- if (rval > max || rval < min) {
+ if (endptr == str || (*endptr != '\0' && *endptr != '\n')) {
tst_brkm_(file, lineno, TBROK, cleanup_fn,
- "strtoul(%s): %lu is out of range %lu - %lu",
- str, rval, min, max);
+ "Invalid value: '%s'", str);
return 0;
}
- if (endptr == str || (*endptr != '\0' && *endptr != '\n')) {
+ if (rval > max || rval < min) {
tst_brkm_(file, lineno, TBROK, cleanup_fn,
- "Invalid value: '%s'", str);
+ "strtoul(%s): %lu is out of range %lu - %lu",
+ str, rval, min, max);
return 0;
}
we need to check the return value before the checking of the endptr, otherwise, it will report out of range when calling of SAFE_STRTOUL("a100", 1, 10000000): TBROK: strtoul(a100): 0 is out of range 1 - 10000000 and it is expected that reported as: TBROK: Invalid value: 'a100' Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com> --- lib/safe_macros.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) -- 2.17.1