Fix LoadString/File bug with parent and non-conforming XML data.

web
Michael R Sweet 21 years ago
parent 4dbac7157e
commit ad9728c731
  1. 5
      CHANGES
  2. 6
      mxml-file.c
  3. 51
      testmxml.c

@ -1,8 +1,11 @@
README - 12/02/2003 README - 12/13/2003
------------------- -------------------
CHANGES IN Mini-XML 1.3 CHANGES IN Mini-XML 1.3
- mxmlLoadString/File() would crash when loading non-
conformant XML data under an existing parent (top)
node.
- Fixed several bugs in the mxmldoc utility. - Fixed several bugs in the mxmldoc utility.
- Added new error callback function to catch a variety - Added new error callback function to catch a variety
of errors and log them to someplace other than stderr. of errors and log them to someplace other than stderr.

@ -1,5 +1,5 @@
/* /*
* "$Id: mxml-file.c,v 1.23 2003/12/03 03:59:04 mike Exp $" * "$Id: mxml-file.c,v 1.24 2003/12/13 16:32:42 mike Exp $"
* *
* File loading code for mini-XML, a small XML-like file parsing library. * File loading code for mini-XML, a small XML-like file parsing library.
* *
@ -817,7 +817,7 @@ mxml_load_data(mxml_node_t *top, /* I - Top node */
if (parent) if (parent)
{ {
while (parent->parent != top) while (parent->parent != top && parent->parent)
parent = parent->parent; parent = parent->parent;
} }
@ -1661,5 +1661,5 @@ mxml_write_ws(mxml_node_t *node, /* I - Current node */
/* /*
* End of "$Id: mxml-file.c,v 1.23 2003/12/03 03:59:04 mike Exp $". * End of "$Id: mxml-file.c,v 1.24 2003/12/13 16:32:42 mike Exp $".
*/ */

@ -1,5 +1,5 @@
/* /*
* "$Id: testmxml.c,v 1.12 2003/07/27 23:11:40 mike Exp $" * "$Id: testmxml.c,v 1.13 2003/12/13 16:32:42 mike Exp $"
* *
* Test program for mini-XML, a small XML-like file parsing library. * Test program for mini-XML, a small XML-like file parsing library.
* *
@ -47,6 +47,7 @@ int /* O - Exit status */
main(int argc, /* I - Number of command-line args */ main(int argc, /* I - Number of command-line args */
char *argv[]) /* I - Command-line args */ char *argv[]) /* I - Command-line args */
{ {
int i; /* Looping var */
FILE *fp; /* File to read */ FILE *fp; /* File to read */
mxml_node_t *tree, /* XML tree */ mxml_node_t *tree, /* XML tree */
*node; /* Node which should be in test.xml */ *node; /* Node which should be in test.xml */
@ -105,6 +106,15 @@ main(int argc, /* I - Number of command-line args */
mxmlNewReal(tree, 123.4f); mxmlNewReal(tree, 123.4f);
mxmlNewText(tree, 1, "text"); mxmlNewText(tree, 1, "text");
mxmlLoadString(tree, "<group>string string string</group>",
MXML_NO_CALLBACK);
mxmlLoadString(tree, "<group>1 2 3</group>",
MXML_INTEGER_CALLBACK);
mxmlLoadString(tree, "<group>1.0 2.0 3.0</group>",
MXML_REAL_CALLBACK);
mxmlLoadString(tree, "<group>opaque opaque opaque</group>",
MXML_OPAQUE_CALLBACK);
node = tree->child; node = tree->child;
if (!node) if (!node)
@ -211,10 +221,39 @@ main(int argc, /* I - Number of command-line args */
return (1); return (1);
} }
mxmlDelete(tree->child); for (i = 0; i < 4; i ++)
mxmlDelete(tree->child); {
mxmlDelete(tree->child); node = node->next;
mxmlDelete(tree->child);
if (!node)
{
fprintf(stderr, "ERROR: No group #%d child node in basic test!\n", i + 1);
mxmlDelete(tree);
return (1);
}
if (node->type != MXML_ELEMENT)
{
fprintf(stderr, "ERROR: Group child #%d has type %s (%d), expected MXML_ELEMENT!\n",
i + 1, node->type < MXML_ELEMENT || node->type > MXML_TEXT ?
"UNKNOWN" : types[node->type], node->type);
mxmlDelete(tree);
return (1);
}
}
for (i = 0; i < 8; i ++)
{
if (tree->child)
mxmlDelete(tree->child);
else
{
fprintf(stderr, "ERROR: Child pointer prematurely NULL on child #%d\n",
i + 1);
mxmlDelete(tree);
return (1);
}
}
if (tree->child) if (tree->child)
{ {
@ -392,5 +431,5 @@ whitespace_cb(mxml_node_t *node, /* I - Element node */
/* /*
* End of "$Id: testmxml.c,v 1.12 2003/07/27 23:11:40 mike Exp $". * End of "$Id: testmxml.c,v 1.13 2003/12/13 16:32:42 mike Exp $".
*/ */

Loading…
Cancel
Save