Developer forums (C::B DEVELOPMENT STRICTLY!) > Plugins development
error in wxSmith - wxsitem.cpp
frithjofh:
Hi again,
after giving it another thought, I only changed the function locally that generates the float representation as string.
I used the <clocale> localeconv() function to find the current decimal separator symbol and do a replace. Not elegant, but it seems to work. I think it does not interfere with threads or events.
See the attached patch file...
regards
frithjof
PS: I think however that there are problems in wxSmith like not checking if input are valid at all, like numbers, that are out of range, and such things. It makes heavy use of rather complicated macros too ...
oBFusCATed:
localeconv() is not thread safe, too. Also what happens if the functions returns NULL, no checks?
frithjofh:
I agree, but localeconv() is only used to read a value, not to alter a value in any way. So I think other threads are not affected. Why would it not be thread save, where is the link I'm missing?
Your second thought about the function returning NULL I don't quite understand well. If localecon() would return NULL, what would have to happen for it to do so? I might think that if this happens the app itself has another problem already. But checking for return of NULL should not be a problem. I'll make an according change ...
Regards
frithjofh
oBFusCATed:
http://www.cplusplus.com/reference/clibrary/clocale/localeconv/
The proper fix is probably to save the decimal separator in a variable at the beginning and then use the variable
frithjofh:
at the beginning of where? the plugin? the entry of the function or the switch case? a const static variable of the function? what do you feel would be the best point?
I also have to admit that I don't like this function very much. According to the wxSplitterwindow reference the particular value should be between 0.0 and 1.0 both included, but it does not even say explicitly how many digits it should have, that is to say what stepping it accepts.
PS: about threads: any manipulation of the locale in another thread would change the result of localeconv() here. But the decimal separator always returns a char, if I understood right, under every possible locale, never an empty.
PS: perhaps a better way would be to parse the double into a wxString manually, composing the string by getting the integer value from the double, add a point, and the decimals from the double, all retrieved separately?
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version