← Back to team overview

zorba-coders team mailing list archive

[Merge] lp:~zorba-coders/zorba/markos-scratch into lp:zorba

 

Markos Zaharioudakis has proposed merging lp:~zorba-coders/zorba/markos-scratch into lp:zorba.

Commit message:
fixed memory error in UserDefinedXQType::isSuperTypeOf()

Requested reviews:
  Markos Zaharioudakis (markos-za)

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/markos-scratch/+merge/167176

fixed memory error in UserDefinedXQType::isSuperTypeOf()
-- 
https://code.launchpad.net/~zorba-coders/zorba/markos-scratch/+merge/167176
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'ChangeLog'
--- ChangeLog	2013-05-24 20:45:21 +0000
+++ ChangeLog	2013-06-03 23:06:31 +0000
@@ -22,6 +22,8 @@
   * Fixed implementation of fn:deep-equal according to latest W3C spec.
   * Must apply document ordering on the domain expression of a FOR clause, if
     the FOR clause is followed by a sequential clause.
+  * Fixed invalid memory access error occuring during sequence type matching
+    for user-defined types.
 
 
 version 2.9

=== modified file 'src/types/typeimpl.cpp'
--- src/types/typeimpl.cpp	2013-05-21 21:44:25 +0000
+++ src/types/typeimpl.cpp	2013-06-03 23:06:31 +0000
@@ -1500,26 +1500,26 @@
 ********************************************************************************/
 bool UserDefinedXQType::isSuperTypeOf(
     const TypeManager* tm,
-    const XQType& subType,
+    const XQType* subType,
     const QueryLoc& loc) const
 {
-  if (isUnion() && isGenAtomicAny() && subType.isAtomicAny())
+  if (isUnion() && isGenAtomicAny() && subType->isAtomicAny())
   {
     std::vector<xqtref_t>::const_iterator ite = m_unionItemTypes.begin();
     std::vector<xqtref_t>::const_iterator end = m_unionItemTypes.end();
     for (; ite != end; ++ite)
     {
-      if (TypeOps::is_subtype(tm, subType, *(*ite), loc))
+      if (TypeOps::is_subtype(tm, *subType, *(*ite), loc))
         return true;
     }
 
     return false;
   }
 
-  if (subType.type_kind() != XQType::USER_DEFINED_KIND)
+  if (subType->type_kind() != XQType::USER_DEFINED_KIND)
     return false;
 
-  const UserDefinedXQType* subtype = static_cast<const UserDefinedXQType*>(&subType);
+  const UserDefinedXQType* subtype = static_cast<const UserDefinedXQType*>(subType);
 
   do
   {
@@ -1529,14 +1529,13 @@
       return true;
     }
 
-    if (subtype->type_kind() == XQType::USER_DEFINED_KIND)
-    {
-      subtype = static_cast<const UserDefinedXQType*>(subtype->getBaseType().getp());
-    }
-    else
-    {
+    subType = subtype->getBaseType().getp();
+
+    if (subType->type_kind() != XQType::USER_DEFINED_KIND)
       return false;
-    }
+
+    subtype = static_cast<const UserDefinedXQType*>(subType);
+
   }
   while (subtype != NULL);
 

=== modified file 'src/types/typeimpl.h'
--- src/types/typeimpl.h	2013-05-21 21:44:25 +0000
+++ src/types/typeimpl.h	2013-06-03 23:06:31 +0000
@@ -802,7 +802,7 @@
 
   bool isSuperTypeOf(
       const TypeManager* tm,
-      const XQType& subType,
+      const XQType* subType,
       const QueryLoc& loc) const;
 
   bool isSubTypeOf(const TypeManager* tm, const XQType& superType) const;

=== modified file 'src/types/typeops.cpp'
--- src/types/typeops.cpp	2013-04-23 20:38:23 +0000
+++ src/types/typeops.cpp	2013-06-03 23:06:31 +0000
@@ -486,9 +486,7 @@
     case XQType::ANY_FUNCTION_TYPE_KIND:
     case XQType::EMPTY_KIND:
     case XQType::STRUCTURED_ITEM_KIND:
-#ifdef ZORBA_WITH_JSON
     case XQType::JSON_TYPE_KIND:
-#endif
       return true;
       
     case XQType::USER_DEFINED_KIND:
@@ -577,9 +575,7 @@
     case XQType::NODE_TYPE_KIND:
     case XQType::EMPTY_KIND:
     case XQType::STRUCTURED_ITEM_KIND:
-#ifdef ZORBA_WITH_JSON
     case XQType::JSON_TYPE_KIND:
-#endif
       return true;
 
     default:
@@ -590,7 +586,6 @@
     break;
   }
 
-#ifdef ZORBA_WITH_JSON
   case XQType::JSON_TYPE_KIND:
   {
     if (subtype.type_kind() != XQType::JSON_TYPE_KIND)
@@ -615,7 +610,6 @@
       ZORBA_ASSERT(false);
     }
   }
-#endif
 
   case XQType::NODE_TYPE_KIND:
   {
@@ -656,9 +650,7 @@
 
     case XQType::NODE_TYPE_KIND:
     case XQType::ITEM_KIND:
-#ifdef ZORBA_WITH_JSON
     case XQType::JSON_TYPE_KIND:
-#endif
     case XQType::STRUCTURED_ITEM_KIND:
       return false;
 
@@ -710,7 +702,7 @@
     const UserDefinedXQType& udt = 
     static_cast<const UserDefinedXQType&>(supertype);
 
-    return udt.isSuperTypeOf(tm, subtype, loc);
+    return udt.isSuperTypeOf(tm, &subtype, loc);
   }
   
   default:
@@ -822,17 +814,12 @@
 
   case XQType::STRUCTURED_ITEM_KIND:
   {
-#ifdef ZORBA_WITH_JSON
     if (subitem->isStructuredItem())
-#else
-    if (subitem->isNode())
-#endif
       return true;
 
     return false;
   }
 
-#ifdef ZORBA_WITH_JSON
   case XQType::JSON_TYPE_KIND:
   {
     if (!subitem->isJSONItem())
@@ -856,7 +843,6 @@
       ZORBA_ASSERT(false);
     }
   }
-#endif
 
   case XQType::NODE_TYPE_KIND:
   {
@@ -904,7 +890,7 @@
     const UserDefinedXQType& udSuperType = 
     static_cast<const UserDefinedXQType&>(supertype);
 
-    return udSuperType.isSuperTypeOf(tm, *subtype, loc);
+    return udSuperType.isSuperTypeOf(tm, subtype.getp(), loc);
   }
 
   default:


Follow ups