Hi Bruno, On Thu, Jul 18, 2024 at 08:06:07PM GMT, Bruno Haible wrote: > Alejandro Colomar wrote: > > If xstrtol() was being called with a base of 1, under some conditions it > > would invoke Undefined Behavior. > > Yes, sure. A numeric base of 1 makes no sense, mathematically. > > Thanks for the patch; applied. > > Note that I disagree with the statement from > https://github.com/void-linux/void-packages/issues/51261#issuecomment-2237055195 > : > > Yet he introduced that bug a decade ago > > I wouldn't call it a bug. Gnulib does not document that passing a base of 1 > to xstrtol is valid.
While it's your api, borrowing the name of strtol(3) comes with implied semantics. I think it'd be common to assume that unless specifically documented, you behave like POSIX's strtol(3), which produces defined behavior for a base of 1. If not a bug, it was at least misleading. I don't claim that POSIX's choice was good; actually I think it makes little sense, and ISO C's choice of leaving it undefined was probably better. BTW, does gnulib have documentation for xstrtol()? I couldn't find it. And for MALLOC()? I'm interested in reading both. > It's known to everyone in the field that a base of 1 > makes no sense. So, what you saw here was a slightly incomplete input > validation check. > > Thanks for the improvement. You're welcome! Have a lovely night! Alex > Bruno -- <https://www.alejandro-colomar.es/>
signature.asc
Description: PGP signature