by haberman · 4y ago · 0 comments
This is bad for not only performance, but correctness. If you are writing a JSON serializer and you use sprintf() to format float/double values, someone can make you produce incorrect output by setting the locale to something that uses "," as a decimal separator.
And there is no way to turn this off!
This is one moment where the difference between an application language and a system language seems clear. An application language could maybe assume that string formatting is for showing to a user. A systems language should assume that you are implementing protocols, and that mere user preference should not change your output.
That turns it off pretty well. Even if other libs call setlocale (looking at you, gtk), they'll get your version.
like so: https://github.com/smcameron/space-nerds-in-space/blob/maste...
It took surprisingly long to track down, partially due to this all being dependent on various ambient Information (env vars, browser config, arguments passed, what exact function is called, etc).
Install linux on your laptop, seeing the source code is worth it.