Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalidated parent pointers if child array is reallocated #25

Open
tbeu opened this issue Apr 13, 2018 · 0 comments
Open

Invalidated parent pointers if child array is reallocated #25

tbeu opened this issue Apr 13, 2018 · 0 comments

Comments

@tbeu
Copy link
Contributor

tbeu commented Apr 13, 2018

During parsing, if in XmlNode_createChild cpo_array_preallocate is called by cpo_array_push in line

XmlNodeRef child = cpo_array_push( node->m_childs );

the m_parent pointer is invalidated (due to the realloc) for all grand-children of that node.

To reproduce: This happens with the attached xml file, where dummyRoot/set1 has 9 (> XMLTREE_CHILDSIZE = 8) children. When XmlNode_createChild is called for dummyRoot/set1/clock8 the m_parent gets invalidated for dummyRoot/gain/k etc.

testFAIL.zip

Currently, I have no patch for this, just the workaround to not use the parent pointer at all.

Furthermore, the reallocated memory in cpo_array_preallocate should also be nullified (similar as cpo_array_create calls calloc for a->v).

--- "a/array.c"
+++ "b/array.c"
@@ -54,6 +54,7 @@ static int cpo_array_preallocate(cpo_array_t *a, asize_t elements)
         free(a->v);
 
     a->v = newv;
+    memset((unsigned char*) a->v + a->elem_size * a->max, 0, (newmax - a->max) * a->elem_size);
     a->max = newmax;
     return 0;
 } 

See modelica-3rdparty/ExternData#26 for the downstream issue.

tbeu added a commit to modelica-3rdparty/ExternData that referenced this issue Apr 13, 2018
Workaround for upstream issue bsapundzhiev/bsxml-json#25: Do not call XmlNode_getParent, which may return invalid pointer
tbeu added a commit to modelica-3rdparty/ExternData that referenced this issue Apr 16, 2018
Workaround for upstream issue bsapundzhiev/bsxml-json#25: Do not call XmlNode_getParent, which may return invalid pointer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant