SuperHouse / esp-open-rtos

Open source FreeRTOS-based ESP8266 software framework
BSD 3-Clause "New" or "Revised" License
1.54k stars 489 forks source link

libc bug with locale.h #494

Open Zaltora opened 7 years ago

Zaltora commented 7 years ago

I found a bug, i post here but not sure if it is related to esp-open-rtos. I was trying #include <locale.h> I want to change "." into "," when using float and printf, sprintf, ... In my main, i do this :

struct lconv* locale = localeconv();
locale->decimal_point = "," ;  //Printf float with a coma

After this, printf and sprintf work well, using coma instead of dot. but the function sscanf (maybe scanf ? ) didn't work with float. Example : before (with dot config):
=> sscanf( "123.123", "%f", &value) => value = 123.123 (Dot) after (with coma config) : => sscanf( "123,123", "%f", &value) => value = 123,0 (Coma) => sscanf( "123.123", "%f", &value) => value = 123.0 (Dot)

ourairquality commented 7 years ago

This limitation is due to the default newlib being built to use the 'nano' io functions, see stdio/nano-vfscanf_float.c which hard codes the decimal point character. So if this is important you will need to recompile newlib configured not to use the nano variants, and then you might find that it does not link, overflows the iram, so might have the remove printf from iram too.

Zaltora commented 6 years ago

If it is hard coded, why use dot with sscanf don't work ? ( this function call other things that need coma ? ) My solutions:

Thank for your help!