Commit Graph

4 Commits

Author SHA1 Message Date
Yuxuan Shui 8f3aa1ee32
Parse number locale-independently
Previously we were using glibc's strtod function to parse floating point
numbers. The problem is, strtod is locale dependent. Meaning 7,7 might
be parsed as two numbers (7 and 7) in one locale, and parsed as one
number (7 point 7) in another locale. This is undesirable.

We need to set the locale to a value we know to make number parsing
consistently. We could use setlocale(), but that is not thread-safe. We
can also use uselocale(), which is thread-safe, but doesn't cover strtod
(Yeah, some of the locale-aware functions only acknowledge the global
locale, not the thread local one).

So in frustration, I just wrote a simple floating point number parser
myself. This parser obviously doesn't cover all cases strtod covers, but
is good enough for our needs.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
2019-02-02 01:43:07 +00:00
Yuxuan Shui 1ea611c90e
Improved allocation failure reporting
Now it reports file and line number of the function too.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
2018-12-20 14:19:10 +00:00
Yuxuan Shui b73dce1d6d
Replace mstrcpy, mstrncpy with strdup, strndup
Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
2018-12-15 19:07:14 +00:00
Yuxuan Shui 0cebbc370a
Function movements
* string functions mstr*() are moved to string_utils.c
* allocation wrappers are moved to utils.h
* printf_* functions are moved to log.h

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
2018-12-15 17:43:36 +00:00