[Tarantool-patches] [PATCH luajit] Give expected results for negative non-base-10 numbers in tonumber().

Igor Munkin imun at tarantool.org
Mon Jun 27 23:58:32 MSK 2022


Sergey,

Thanks for the patch! LGTM, except a single nit I've fixed by myself.

On 27.12.21, Sergey Kaplun wrote:
> From: Mike Pall <mike>
> 
> This was undefined in Lua 5.1, but it's defined in 5.2.
> 
> (cherry picked from f3cf0d6e15240098147437fed7bd436ff55fdf8c)
> 
> `strtoul()` considers negative values as a valid input and silently
> converts them to the equivalent unsigned long value. As a result yielded
> value is unexpected to the user.
> 
> This patch adds reading of a sign (if exists) from argument and provide

Typo: s/provide/provides/.

> the remaining part of the string as is if it starts with a digit or
> alphabetical symbol to be consistent with Lua 5.2.
> 
> Sergey Kaplun:
> * added the description and the test for the problem
> 
> Part of tarantool/tarantool#6548
> ---
> 
> Issue: https://github.com/tarantool/tarantool/issues/6548
> Branch: https://github.com/tarantool/luajit/tree/skaplun/gh-noticket-tonumber-expected-results-full-ci
> Tarantool branch: https://github.com/tarantool/tarantool/tree/skaplun/gh-noticket-tonumber-expected-results-full-ci
> 
> CI is red due to integration tests failes (same as on master) or due to
> connection errors.
> 
> Side note: I suppose that undefinence Mike talking about is the
> following lines in the Lua 5.1 Reference manual [1]:
> 
> | In base 10 (the default), the number can have a decimal part, as well
> | as an optional exponent part (see paragraph 2.1). In other bases, only
> | unsigned integers are accepted.
> 
> In the Lua 5.2 Reference manual [2] they are deleted.
> 
>  src/lib_base.c                                | 27 +++++++++++------
>  ...onumber-negative-non-decimal-base.test.lua | 29 +++++++++++++++++++
>  2 files changed, 47 insertions(+), 9 deletions(-)
>  create mode 100644 test/tarantool-tests/tonumber-negative-non-decimal-base.test.lua
> 

<snipped>

> -- 
> 2.34.1
> 
> [1]: http://www.lua.org/manual/5.1/manual.html#pdf-tonumber
> [2]: http://www.lua.org/manual/5.2/manual.html#pdf-tonumber

-- 
Best regards,
IM


More information about the Tarantool-patches mailing list