mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Warn about commas in floating point values
Localization could be causing floating point numbers to have a comma instead of a decimal point (in a file format that is really stupid). If we detect this we replace the comma with a decimal point instead, and try to re-parse the number, and see if we get further. The downside of that is that we're changing the buffer we get passed in. Nobody cares, but still, it's kind of ugly. It's simple, though. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
29be221bd8
commit
f1f667c96f
1 changed files with 15 additions and 0 deletions
15
parse-xml.c
15
parse-xml.c
|
@ -207,11 +207,26 @@ enum number_type {
|
|||
static enum number_type parse_float(char *buffer, double *res, char **endp)
|
||||
{
|
||||
double val;
|
||||
static gboolean first_time = TRUE;
|
||||
|
||||
errno = 0;
|
||||
val = g_ascii_strtod(buffer, endp);
|
||||
if (errno || *endp == buffer)
|
||||
return NEITHER;
|
||||
if (**endp == ',') {
|
||||
if (val == rint(val)) {
|
||||
/* we really want to send an error if this is a Subsurface native file
|
||||
* as this is likely indication of a bug - but right now we don't have
|
||||
* that information available */
|
||||
if (first_time) {
|
||||
fprintf(stderr, "Floating point value with decimal comma (%s)?\n", buffer);
|
||||
first_time = FALSE;
|
||||
}
|
||||
/* Try again */
|
||||
**endp = '.';
|
||||
val = g_ascii_strtod(buffer, endp);
|
||||
}
|
||||
}
|
||||
|
||||
*res = val;
|
||||
return FLOAT;
|
||||
|
|
Loading…
Add table
Reference in a new issue