[cpp-xmltooling COMMIT] in /branches/REL_1/xmltooling: base.h util/XMLHelper.cpp

noreply at shibboleth.net noreply at shibboleth.net
Sun Jul 5 15:11:33 EDT 2015


Author: scantor
Date: Sun Jul  5 15:11:33 2015
New Revision: 1058

URL: http://svn.shibboleth.net/view/cpp-xmltooling?rev=1058&view=rev
Log:
CPPXT-104 - Add exception handling to integer conversions

Modified:
    branches/REL_1/xmltooling/base.h
    branches/REL_1/xmltooling/util/XMLHelper.cpp

Modified: branches/REL_1/xmltooling/base.h
URL: http://svn.shibboleth.net/view/cpp-xmltooling/branches/REL_1/xmltooling/base.h?rev=1058&r1=1057&r2=1058&view=diff
==============================================================================
--- branches/REL_1/xmltooling/base.h	(original)
+++ branches/REL_1/xmltooling/base.h	Sun Jul  5 15:11:33 2015
@@ -811,7 +811,16 @@
         XMLCh* m_##proper; \
     public: \
         pair<bool,int> get##proper() const { \
-            return make_pair((m_##proper!=nullptr),(m_##proper!=nullptr ? xercesc::XMLString::parseInt(m_##proper): 0)); \
+            if (m_##proper) { \
+                try { \
+                    return std::make_pair(true, xercesc::XMLString::parseInt(m_##proper)); \
+                } \
+                catch (...) { \
+                    return std::make_pair(true, 0); \
+                } \
+            } else { \
+                return std::make_pair(false, 0); \
+            } \
         } \
         void set##proper(const XMLCh* proper) { \
             m_##proper = prepareForAssignment(m_##proper,proper); \
@@ -1369,7 +1378,16 @@
 #define DECL_INTEGER_CONTENT(proper) \
     XMLTOOLING_DOXYGEN(Returns proper in integer form after a NULL indicator.) \
     std::pair<bool,int> get##proper() const { \
-        return std::make_pair((getTextContent()!=nullptr), (getTextContent()!=nullptr ? xercesc::XMLString::parseInt(getTextContent()) : 0)); \
+        if (getTextContent()) { \
+            try { \
+                return std::make_pair(true, xercesc::XMLString::parseInt(getTextContent())); \
+            } \
+            catch (...) { \
+                return std::make_pair(true, 0); \
+            } \
+        } else { \
+            return std::make_pair(false, 0); \
+        } \
     } \
     XMLTOOLING_DOXYGEN(Sets proper.) \
     void set##proper(int proper) { \

Modified: branches/REL_1/xmltooling/util/XMLHelper.cpp
URL: http://svn.shibboleth.net/view/cpp-xmltooling/branches/REL_1/xmltooling/util/XMLHelper.cpp?rev=1058&r1=1057&r2=1058&view=diff
==============================================================================
--- branches/REL_1/xmltooling/util/XMLHelper.cpp	(original)
+++ branches/REL_1/xmltooling/util/XMLHelper.cpp	Sun Jul  5 15:11:33 2015
@@ -338,9 +338,11 @@
     if (e) {
         const XMLCh* val = e->getAttributeNS(ns, localName);
         if (val && *val) {
-            int i = XMLString::parseInt(val);
-            if (i)
-                return i;
+            try {
+                return XMLString::parseInt(val);
+            }
+            catch (XMLException&) {
+            }
         }
     }
     return defValue;



More information about the commits mailing list