Skip to content

Commit e76fdea

Browse files
committed
interim patch for get_user_vec3d_value
As described in #3079, the old parsing of fvec and uvec used strtod and some POFs rely on this format. This is a quickfix that uses the new parsing method for only `get_user_vec3d_value`.
1 parent 726ce95 commit e76fdea

File tree

1 file changed

+52
-3
lines changed

1 file changed

+52
-3
lines changed

code/model/modelread.cpp

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,55 @@ void get_user_prop_value(char *buf, char *value)
462462
*p1 = c;
463463
}
464464

465+
// Stuff a floating point value pointed at by Mp.
466+
// Advances past float characters.
467+
int stuff_float_temp(float *f, bool optional)
468+
{
469+
char *str_start = Mp;
470+
char *str_end;
471+
472+
// since strtof ignores white space anyway, might as well make it explicit
473+
ignore_white_space();
474+
475+
auto result = strtof(Mp, &str_end);
476+
bool success = false, comma = false;
477+
int retval = 0;
478+
479+
// no float found?
480+
if (result == 0.0f && str_end == Mp)
481+
{
482+
if (!optional)
483+
error_display(1, "Expecting float, found [%.32s].\n", next_tokens());
484+
}
485+
else
486+
{
487+
*f = result;
488+
success = true;
489+
}
490+
491+
if (success)
492+
Mp = str_end;
493+
494+
if (*Mp == ',')
495+
{
496+
comma = true;
497+
Mp++;
498+
}
499+
500+
if (optional && !success)
501+
Mp = str_start;
502+
503+
if (success)
504+
retval = 2;
505+
else if (optional)
506+
retval = comma ? 1 : 0;
507+
else
508+
skip_token();
509+
510+
diag_printf("Stuffed float: %f\n", *f);
511+
return retval;
512+
}
513+
465514
// routine to parse out a vec3d from a user property field of an object
466515
bool get_user_vec3d_value(char *buf, vec3d *value, bool require_brackets)
467516
{
@@ -494,11 +543,11 @@ bool get_user_vec3d_value(char *buf, vec3d *value, bool require_brackets)
494543
}
495544

496545
// get comma-separated floats
497-
if (stuff_float_optional(&f1) != 2)
546+
if (stuff_float_temp(&f1, true) != 2)
498547
break;
499-
if (stuff_float_optional(&f2) != 2)
548+
if (stuff_float_temp(&f2, true) != 2)
500549
break;
501-
if (stuff_float_optional(&f3) != 2)
550+
if (stuff_float_temp(&f3, true) != 2)
502551
break;
503552

504553
if (require_brackets)

0 commit comments

Comments
 (0)