[Kstars-devel] [kstars] kstars/indi: Fixed an issue where atof is not working properly in some locales resulting in inaccurate coordinate conversion from INDI devices. Thanks for Igancio Mas for catching this!

Jasem Mutlaq mutlaqja at ikarustech.com
Sat Nov 12 09:59:18 UTC 2011


Git commit 6eefdf3311be45743763c52ad851b52fd23fc7ee by Jasem Mutlaq.
Committed on 12/11/2011 at 10:55.
Pushed by mutlaqja into branch 'master'.

Fixed an issue where atof is not working properly in some locales resulting in inaccurate coordinate conversion from INDI devices. Thanks for Igancio Mas for catching this!

CCMAIL:kstars-devel at kde.org
CCMAIL:mas.ignacio at gmail.com

M  +12   -0    kstars/indi/indidevice.cpp
M  +4    -0    kstars/indi/indiproperty.cpp

http://commits.kde.org/kstars/6eefdf3311be45743763c52ad851b52fd23fc7ee

diff --git a/kstars/indi/indidevice.cpp b/kstars/indi/indidevice.cpp
index c46c7e1..60c6437 100644
--- a/kstars/indi/indidevice.cpp
+++ b/kstars/indi/indidevice.cpp
@@ -212,7 +212,11 @@ int INDI_D::setValue (INDI_P *pp, XMLEle *root, QString & errmsg)
     /* allow changing the timeout */
     ap = findXMLAtt (root, "timeout");
     if (ap)
+    {
+        setlocale(LC_NUMERIC,"C");
         pp->timeout = atof(valuXMLAtt(ap));
+        setlocale(LC_NUMERIC,"");
+    }
 
     /* process specific GUI features */
     switch (pp->guitype)
@@ -257,6 +261,9 @@ int INDI_D::setTextValue (INDI_P *pp, XMLEle *root, QString & errmsg)
     char iNumber[32];
     double min, max;
 
+    // Ensure that atof works with decimal points
+    setlocale(LC_NUMERIC,"C");
+
     for (ep = nextXMLEle (root, 1); ep != NULL; ep = nextXMLEle (root, 0))
     {
         if (strcmp (tagXMLEle(ep), "oneText") && strcmp(tagXMLEle(ep), "oneNumber"))
@@ -291,6 +298,7 @@ int INDI_D::setTextValue (INDI_P *pp, XMLEle *root, QString & errmsg)
             }
             else if (pp->guitype == PG_NUMERIC)
             {
+
                 lp->value = atof(pcdataXMLEle(ep));
                 numberFormat(iNumber, lp->format.toAscii(), lp->value);
                 lp->text = iNumber;
@@ -341,6 +349,8 @@ int INDI_D::setTextValue (INDI_P *pp, XMLEle *root, QString & errmsg)
     // suppress warning
     errmsg = errmsg;
 
+    setlocale(LC_NUMERIC,"");
+
     return (0);
 }
 
@@ -655,7 +665,9 @@ INDI_P * INDI_D::addProperty (XMLEle *root, QString & errmsg)
     /* init timeout */
     ap = findAtt (root, "timeout", errmsg);
     /* default */
+    setlocale(LC_NUMERIC,"C");
     pp->timeout = ap ? atof(valuXMLAtt(ap)) : 0;
+    setlocale(LC_NUMERIC,"");
 
     /* log any messages */
     deviceManager->checkMsg (root, this);
diff --git a/kstars/indi/indiproperty.cpp b/kstars/indi/indiproperty.cpp
index c79cae3..f9acf40 100644
--- a/kstars/indi/indiproperty.cpp
+++ b/kstars/indi/indiproperty.cpp
@@ -504,6 +504,8 @@ int INDI_P::buildNumberGUI  (XMLEle *root, QString & errmsg)
     INDI_E *lp;
     QString numberName, numberLabel;
 
+    setlocale(LC_NUMERIC,"C");
+
     for (number = nextXMLEle (root, 1); number != NULL; number = nextXMLEle (root, 0))
     {
         if (strcmp (tagXMLEle(number), "defNumber"))
@@ -558,6 +560,8 @@ int INDI_P::buildNumberGUI  (XMLEle *root, QString & errmsg)
 
     }
 
+    setlocale(LC_NUMERIC,"");
+
     if (perm == PP_RO)
         return 0;
 


More information about the Kstars-devel mailing list