diff options
-rw-r--r-- | connectivity/inc/connectivity/sqlnode.hxx | 8 | ||||
-rw-r--r-- | connectivity/source/parse/sqlnode.cxx | 12 |
2 files changed, 13 insertions, 7 deletions
diff --git a/connectivity/inc/connectivity/sqlnode.hxx b/connectivity/inc/connectivity/sqlnode.hxx index e21e06e31515..4082375051fb 100644 --- a/connectivity/inc/connectivity/sqlnode.hxx +++ b/connectivity/inc/connectivity/sqlnode.hxx @@ -130,7 +130,10 @@ namespace connectivity public: enum Rule { - select_statement = 0, + UNKNOWN_RULE = 0, // ID indicating that a node is no rule with a matching Rule-enum value (see getKnownRuleID) + // we make sure it is 0 so that it is the default-constructor value of this enum + // and std::map<foo,Rule>::operator[](bar) default-inserts UNKNOWN_RULE rather than select_statement (!) + select_statement, table_exp, table_ref_commalist, table_ref, @@ -229,8 +232,7 @@ namespace connectivity other_like_predicate_part_2, between_predicate_part_2, cast_spec, - rule_count, // last value - UNKNOWN_RULE = -1 // ID indicating that a node is no rule with a matching Rule-enum value (see getKnownRuleID) + rule_count // last value }; // must be ascii encoding for the value diff --git a/connectivity/source/parse/sqlnode.cxx b/connectivity/source/parse/sqlnode.cxx index ae9f3f1fe72a..ca2281a0708a 100644 --- a/connectivity/source/parse/sqlnode.cxx +++ b/connectivity/source/parse/sqlnode.cxx @@ -59,6 +59,7 @@ #include <tools/diagnose_ex.h> #include <string.h> #include <boost/bind.hpp> +#include <boost/static_assert.hpp> #include <algorithm> #include <functional> #include <rtl/logfile.hxx> @@ -1289,8 +1290,9 @@ OSQLParser::OSQLParser(const ::com::sun::star::uno::Reference< ::com::sun::star: if(!s_xLocaleData.is()) s_xLocaleData = LocaleData::create(m_xContext); - // reset to 0 - memset(OSQLParser::s_nRuleIDs,0,sizeof(OSQLParser::s_nRuleIDs[0]) * (OSQLParseNode::rule_count+1)); + // reset to UNKNOWN_RULE + BOOST_STATIC_ASSERT(OSQLParseNode::UNKNOWN_RULE==0); + memset(OSQLParser::s_nRuleIDs,0,sizeof(OSQLParser::s_nRuleIDs)); struct { @@ -1398,8 +1400,10 @@ OSQLParser::OSQLParser(const ::com::sun::star::uno::Reference< ::com::sun::star: { OSQLParseNode::between_predicate_part_2, "between_predicate_part_2" }, { OSQLParseNode::cast_spec, "cast_spec" } }; - size_t nRuleMapCount = sizeof( aRuleDescriptions ) / sizeof( aRuleDescriptions[0] ); - OSL_ENSURE( nRuleMapCount == size_t( OSQLParseNode::rule_count ), "OSQLParser::OSQLParser: added a new rule? Adjust this map!" ); + const size_t nRuleMapCount = sizeof( aRuleDescriptions ) / sizeof( aRuleDescriptions[0] ); + // added a new rule? Adjust this map! + // +1 for UNKNOWN_RULE + BOOST_STATIC_ASSERT( nRuleMapCount + 1 == static_cast<size_t>(OSQLParseNode::rule_count) ); for ( size_t mapEntry = 0; mapEntry < nRuleMapCount; ++mapEntry ) { |