From eada74ac651ee1885d8b135fa59c6f9482bb08fb Mon Sep 17 00:00:00 2001 From: Andrzej Surdej Date: Wed, 22 May 2013 17:37:23 +0200 Subject: [PATCH] Fix for wiget parser. [Issue#] N/A [Problem] When checking 'update-period' the decimal point mark various in different locales. [Cause] strdot() uses locales when converting string to double. [Solution] Set standard "C" locales on parsing time. [Verification] To verify install new-app-widget* attached in https://tizendev.org/bugs/browse/TDIS-5713. Both should be able to install. Change-Id: I4c4d67e96845c16b66f4c91b8e17c67dab77c05a --- src/configuration_parser/widget_parser.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/configuration_parser/widget_parser.cpp b/src/configuration_parser/widget_parser.cpp index 4404aa6..9691f0f 100644 --- a/src/configuration_parser/widget_parser.cpp +++ b/src/configuration_parser/widget_parser.cpp @@ -46,6 +46,7 @@ #include #include #include +#include using namespace WrtDB; @@ -2034,17 +2035,24 @@ class AppWidgetParser : public ElementParser if (!m_updatePeriod.empty()) { char * endptr; + errno = 0; std::string tempStr = DPL::ToUTF8String(m_updatePeriod); - const char * up_cstr = tempStr.c_str(); - errno = 0; - double update_period = strtod(up_cstr, &endptr); + //set standard locale to fix decimal point mark - '.' + std::string currentLocale = setlocale(LC_NUMERIC, NULL); + if (NULL == setlocale(LC_NUMERIC, "C")) + LogWarning("Failed to change locale to \"C\""); + double updatePeriod = strtod(tempStr.c_str(), &endptr); + + //go back to previous locale + if (NULL == setlocale(LC_NUMERIC, currentLocale.c_str())) + LogWarning("Failed to set previous locale"); - if ((errno == ERANGE && (update_period == -HUGE_VAL || update_period == HUGE_VAL)) + if ((errno == ERANGE && (updatePeriod == -HUGE_VAL || updatePeriod == HUGE_VAL)) || *endptr != '\0') { ThrowMsg(Exception::ParseError, "update-period attribute of app-widget element should be a number - ignoring. current value: " << m_updatePeriod); - } else if (update_period < 60.0) { + } else if (updatePeriod < 60.0) { LogDebug("update-period attribute of app-widget element shouldn't be less than 60.0 - changed to 60 from value: " << m_updatePeriod); m_updatePeriod = L"60.0"; } -- 2.7.4