Skip to content

Commit ec13897

Browse files
committed
Always Use C style double conversion
Signed-off-by: Maxime Gervais <gervais.maxime@gmail.com>
1 parent 443ec2f commit ec13897

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

Source/Checker/Checker.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,21 @@ bool PolicyChecker::RuleElement::compare(const std::string& v1, const std::stri
307307
{
308308
bool to_return = false;
309309

310-
char* val_end=NULL;
311-
double val = strtod(v2.c_str(), &val_end);
312-
char* ref_end=NULL;
313-
double ref = strtod(v1.c_str(), &ref_end);
310+
// Ensure locale-independent conversion (dot as decimal separator, supports +/- signs)
311+
char* val_end = nullptr;
312+
char* ref_end = nullptr;
313+
#ifdef _WIN32
314+
_locale_t c_locale = _create_locale(LC_NUMERIC, "C");
315+
#else
316+
locale_t c_locale = newlocale(LC_NUMERIC_MASK, "C", nullptr);
317+
#endif // _WIN32
318+
double val = _strtod_l(v2.c_str(), &val_end, c_locale);
319+
double ref = _strtod_l(v1.c_str(), &ref_end, c_locale);
320+
#ifdef _WIN32
321+
_free_locale(c_locale);
322+
#else
323+
freelocale(c_locale);
324+
#endif // _WIN32
314325

315326
if (operand=="starts with")
316327
{

0 commit comments

Comments
 (0)