Fixed bug #341337, reported by David Grohmann. The code expected a node

* xmlschemas.c: Fixed bug #341337, reported by David Grohmann.
  The code expected a node (xmlNodePtr) on the info for a
  non-existent default attribute, which clearly cannot be
  expected, since the attribute does not exist. I can only
  guess that this sneaked trying to eliminate the query
  for the owner-element, which is unavoidable actually.
  Note that creation of default attributes won't have an
  effect if validating via SAX/XMLReader; i.e., the processor
  won't fire additional start-attribute events (I'm not even
  sure if Libxml2 has such a SAX-event; I think it hands them
  all over in the start-element event).
diff --git a/xmlschemas.c b/xmlschemas.c
index 164191d..c51e103 100644
--- a/xmlschemas.c
+++ b/xmlschemas.c
@@ -24823,9 +24823,10 @@
     xmlSchemaItemListPtr attrUseList;
     xmlSchemaAttributeUsePtr attrUse = NULL;
     xmlSchemaAttributePtr attrDecl = NULL;
-    xmlSchemaAttrInfoPtr iattr, tmpiattr;
+    xmlSchemaAttrInfoPtr iattr, tmpiattr;    
     int i, j, found, nbAttrs, nbUses;
     int xpathRes = 0, res, wildIDs = 0, fixed;
+    xmlNodePtr defAttrOwnerElem = NULL;
 
     /*
     * SPEC (cvc-attribute)
@@ -25068,6 +25069,15 @@
 	return (0);
 
     /*
+    * Get the owner element; needed for creation of default attributes.
+    * This fixes bug #341337, reported by David Grohmann.
+    */
+    if (vctxt->options & XML_SCHEMA_VAL_VC_I_CREATE) {
+	xmlSchemaNodeInfoPtr ielem = vctxt->elemInfos[vctxt->depth];
+	if (ielem && ielem->node && ielem->node->doc)
+	    defAttrOwnerElem = ielem->node;
+    }
+    /*
     * Validate values, create default attributes, evaluate IDCs.
     */
     for (i = 0; i < vctxt->nbAttrInfos; i++) {
@@ -25108,8 +25118,10 @@
 	if (iattr->state == XML_SCHEMAS_ATTR_DEFAULT) {
 	    /*
 	    * Default/fixed attributes.
+	    * We need the value only if we need to resolve IDCs or
+	    * will create default attributes.
 	    */
-	    if (xpathRes) {
+	    if ((xpathRes) || (defAttrOwnerElem)) {
 		if (iattr->use->defValue != NULL) {
 		    iattr->value = (xmlChar *) iattr->use->defValue;
 		    iattr->val = iattr->use->defVal;
@@ -25139,8 +25151,8 @@
 	    * VAL TODO: Should we use the *normalized* value? This currently
 	    *   uses the *initial* value.
 	    */
-	    if ((vctxt->options & XML_SCHEMA_VAL_VC_I_CREATE) &&
-		(iattr->node != NULL) && (iattr->node->doc != NULL)) {
+	    
+	    if (defAttrOwnerElem) {
 		xmlChar *normValue;
 		const xmlChar *value;
 
@@ -25154,7 +25166,7 @@
 		    value = BAD_CAST normValue;
 
 		if (iattr->nsName == NULL) {
-		    if (xmlNewProp(iattr->node->parent,
+		    if (xmlNewProp(defAttrOwnerElem,
 			iattr->localName, value) == NULL) {
 			VERROR_INT("xmlSchemaVAttributesComplex",
 			    "callling xmlNewProp()");
@@ -25165,8 +25177,8 @@
 		} else {
 		    xmlNsPtr ns;
 
-		    ns = xmlSearchNsByHref(iattr->node->doc,
-			iattr->node->parent, iattr->nsName);
+		    ns = xmlSearchNsByHref(defAttrOwnerElem->doc,
+			defAttrOwnerElem, iattr->nsName);
 		    if (ns == NULL) {
 			xmlChar prefix[12];
 			int counter = 0;
@@ -25177,8 +25189,8 @@
 			*/
 			do {
 			    snprintf((char *) prefix, 12, "p%d", counter++);
-			    ns = xmlSearchNs(iattr->node->doc,
-				iattr->node->parent, BAD_CAST prefix);
+			    ns = xmlSearchNs(defAttrOwnerElem->doc,
+				defAttrOwnerElem, BAD_CAST prefix);
 			    if (counter > 1000) {
 				VERROR_INT(
 				    "xmlSchemaVAttributesComplex",
@@ -25198,8 +25210,7 @@
 		    * If we have QNames: do we need to ensure there's a
 		    * prefix defined for the QName?
 		    */
-		    xmlNewNsProp(iattr->node->parent, ns,
-			iattr->localName, value);
+		    xmlNewNsProp(defAttrOwnerElem, ns, iattr->localName, value);
 		}
 		if (normValue != NULL)
 		    xmlFree(normValue);