mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
const'ify our strtod() helper functions
The C library doesn't use const char pointers for legacy reasons (and because you *can* modify the string the end pointer points to), but let's do it in our internal implementation just because it's a nice guarantee to have. We actually used to have a non-const end pointer and replace a decimal comma with a decimal dot, but that was because we didn't have the fancy "allow commas" flags. So by using our own strtod_flags() function, we can now keep all the strings we parse read-only rather than modify them as we parse them. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
19b982d3df
commit
2d1d78ebfe
4 changed files with 11 additions and 11 deletions
11
parse-xml.c
11
parse-xml.c
|
@ -263,7 +263,7 @@ enum number_type {
|
|||
FLOAT
|
||||
};
|
||||
|
||||
static enum number_type parse_float(char *buffer, double *res, char **endp)
|
||||
static enum number_type parse_float(const char *buffer, double *res, const char **endp)
|
||||
{
|
||||
double val;
|
||||
static bool first_time = TRUE;
|
||||
|
@ -281,9 +281,8 @@ static enum number_type parse_float(char *buffer, double *res, char **endp)
|
|||
fprintf(stderr, "Floating point value with decimal comma (%s)?\n", buffer);
|
||||
first_time = FALSE;
|
||||
}
|
||||
/* Try again */
|
||||
**endp = '.';
|
||||
val = ascii_strtod(buffer, endp);
|
||||
/* Try again in permissive mode*/
|
||||
val = strtod_flags(buffer, endp, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -297,7 +296,7 @@ union int_or_float {
|
|||
|
||||
static enum number_type integer_or_float(char *buffer, union int_or_float *res)
|
||||
{
|
||||
char *end;
|
||||
const char *end;
|
||||
return parse_float(buffer, &res->fp, &end);
|
||||
}
|
||||
|
||||
|
@ -459,7 +458,7 @@ static void percent(char *buffer, void *_fraction)
|
|||
{
|
||||
fraction_t *fraction = _fraction;
|
||||
double val;
|
||||
char *end;
|
||||
const char *end;
|
||||
|
||||
switch (parse_float(buffer, &val, &end)) {
|
||||
case FLOAT:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue