-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Closed
Labels
bug 🐛Programming errors, that need preferential fixingProgramming errors, that need preferential fixingrelease-criticalutil-lib
Description
on i386 (32 bit x86), this test fails:
$ ./test-parse-util
Assertion 'parse_range("111--123", &lower, &upper) == -ERANGE' failed at src/test/test-parse-util.c:258, function test_parse_range(). Aborting.
Stepping through with gdb shows that the "-123" is not handled correctly in safe_atou:
303 int safe_atou(const char *s, unsigned *ret_u) {
[...]
311 l = strtoul(s, &x, 0);
(gdb) p s
$8 = 0x5658928f "-123"
(gdb) n
313 if (!x || x == s || *x || errno)
(gdb) p x
$9 = 0x56589293 ""
(gdb) p l
$10 = 4294967173
(gdb) p errno
$11 = 0
Thus this expects an ERANGE from strtoul(), but that instead converts it to a positive number. But this actually appears correct: the manpage says:
"The strtoul() function returns either the result of the conversion or, if there was a leading minus sign, the negation of the result of the conversion represented as an unsigned value, unless the original (nonnegated) value would overflow; in the latter case, strtoul() returns ULONG_MAX and sets errno to ERANGE."
So it would seem we need to check for a leading minus sign ourselves?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bug 🐛Programming errors, that need preferential fixingProgramming errors, that need preferential fixingrelease-criticalutil-lib