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

Error: pointer to incomplete class type is not allowed #247

Closed
Opariti opened this issue Feb 20, 2019 · 2 comments
Closed

Error: pointer to incomplete class type is not allowed #247

Opariti opened this issue Feb 20, 2019 · 2 comments
Assignees
Labels
question General usage question

Comments

@Opariti
Copy link

Opariti commented Feb 20, 2019

Hi,
I have successfully used mxml v.2.11 in a C application under Visual Studio 2017, as per the coding guides in the documentation.
Now, I try to bring the application under Visual Studio Code/Windows 10, mxml-3, with MinGW-64 and gcc, doing the makefile myself.
I have one build error, as in this issue title, for the following function:

// Finds a node by name in a given 'tree' memory structure, then changes the value of the node's attribute with a new one
// Returns the whole memory modified tree
`mxml_node_t* changeNodeAttribute(mxml_node_t *tree, const char *nodeName, const char attrName, char newValue) {
mxml_node_t * node = NULL;

node = mxmlFindElement(tree, tree, nodeName, attrName, NULL, MXML_DESCEND);

for (int k = 0; k < node->value.element.num_attrs; k++) {
	if (strcmp(node->value.element.attrs[k].name, attrName) == 0) {
		node->value.element.attrs[k].value = newValue;
		break;
	}
}
return tree;

}`

The errors are issued by node->~ occurencies above.
I have used the right mxml1.dll, referenced its library in the makefile for the linker, also included the mxml.h file, but I'm missing something.
The exact gcc error is the following:

error: dereferencing pointer to incomplete type 'mxml_node_t' {aka 'struct _mxml_node_s'}
  node->value.element.num_attrs;

Thanks

@michaelrsweet
Copy link
Owner

Mini-XML 3.0 (which has not yet been released) requires that you access the members of the mxml_node_t structure through the accessor functions that were introduced in Mini-XML 2.0, in particular to avoid unsafe usage like your above code (which will eventually cause a crash because the value pointers need to be allocated...) The structure itself is no longer part of the public API.

The safe replacement for the code above (which also works in Mini-XML 2.x) is:

node = mxmlFindElement(...);
mxmlElementSetAttr(node, attrName, newValue);
return tree;

@michaelrsweet michaelrsweet self-assigned this Feb 20, 2019
@michaelrsweet michaelrsweet added the question General usage question label Feb 20, 2019
@Opariti
Copy link
Author

Opariti commented Feb 20, 2019

Thanks, it works so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question General usage question
Projects
None yet
Development

No branches or pull requests

2 participants