Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strtod and locale "Malformed number" #677

Closed
morgoth990 opened this issue Sep 19, 2022 · 3 comments
Closed

strtod and locale "Malformed number" #677

morgoth990 opened this issue Sep 19, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@morgoth990
Copy link
Contributor

I'm building luau in a unity3d ilcpp project that internally use setlocale() to simulate c# locale.
Using some language setting like "fr" on the system strtod inside parseNumber is expecting ',' instead '.' and is throwing a "Manfolrmed number" error on float variables.

@morgoth990 morgoth990 added the bug Something isn't working label Sep 19, 2022
@morgoth990
Copy link
Contributor Author

I fixed it calling setlocale(LC_NUMERIC, "C"); because the rest of the project doesn't use any locale specific string parsing/formatting but I don't know if this was already discussed or can be a problem in other projects

@zeux
Copy link
Collaborator

zeux commented Sep 19, 2022

This came up in #473 (fixed in #474) in context of CLI, with a similar fix. I think for now using C locale is the correct fix; correctly parsing numbers with C locale specification without doing that is pretty arduous (Lua tries to replace the dot with the decimal point but there are some potential inaccuracies with that approach wrt handling numbers that have a more complex formatting specification than just a different decimal point) - it might happen at some point but for now it's the best solution.

@UtoECat
Copy link

UtoECat commented Jun 10, 2023

I think for now using C locale is the correct fix

Except when luau is used in a program that manipulates locales in an unpredictable way. I ran into this issue when using luau in a LADSPA plugin (other LADSPA plugins are very fond of changing the locale), so setting the locale there from the start is not a solution. A workaround for me is to replace luai_str2num with a custom localeless implementation, but this source is not tested for number overflow. strtod.h

I also noticed that luau uses strtod directly in Ast/src/Parser.cpp:2101 not through a macro luai_str2num...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

3 participants