1
0
Fork 0

* Setting an error when a node isn't found isn't he best way,

need to find another way to report that.
  * Fix a bug where an error was incorrectly set in xmlNodeCopyName
This commit is contained in:
ehofman 2009-04-20 17:05:03 +00:00 committed by Tim Moore
parent 8dec4a987f
commit 0561c0079a
3 changed files with 21 additions and 17 deletions

View file

@ -310,6 +310,9 @@ xmlNodeCopyName(const void *id, char *buf, size_t buflen)
if (slen > xid->name_len)
{
slen = xid->name_len;
}
else
{
xmlErrorSet(xid, 0, XML_TRUNCATE_RESULT);
}
memcpy(buf, xid->name, slen);
@ -1238,11 +1241,10 @@ static const char *__xml_error_str[XML_MAX_ERROR] =
"no error.",
"unable to allocate enough memory.",
"unable to open file for reading.",
"buffer us too small to hold the result, truncating.",
"buffer too small to hold all data, truncating.",
"incorrect comment section.",
"bad information block.",
"unexpected end of xml section (maybe a missing end tag?)",
"element not found.",
"unexpected end of section.",
"incompatible opening tag for element.",
"missing or invalid closing tag for element.",
"missing or invalid opening quote for attribute.",
@ -1551,7 +1553,7 @@ __xmlNodeGet(const char *start, size_t *len, char **name, size_t *rlen, size_t *
ret = 0;
*rlen = 0;
*name = start_tag;
*len = XML_ELEMENT_NOT_FOUND;
*len = XML_NO_ERROR; /* element not found */
}
else
{

View file

@ -37,7 +37,6 @@ enum
XML_INVALID_COMMENT,
XML_INVALID_INFO_BLOCK,
XML_UNEXPECTED_EOF,
XML_ELEMENT_NOT_FOUND,
XML_ELEMENT_NO_OPENING_TAG,
XML_ELEMENT_NO_CLOSING_TAG,
XML_ATTRIB_NO_OPENING_QUOTE,

View file

@ -26,6 +26,9 @@ static int print_filenames = 0;
static void free_and_exit(int i);
#define NODE_NAME_LEN 256
#define STRING_LEN 2048
#define SHOW_NOVAL(opt) \
{ \
printf("option '%s' requires a value\n\n", (opt)); \
@ -200,9 +203,9 @@ void walk_the_tree(size_t num, void *xid, char *tree)
{
if (xmlNodeGetPos(xid, xmid, _print, i) != 0)
{
char value[1024];
char value[STRING_LEN];
xmlCopyString(xmid, (char *)&value, 1024);
xmlCopyString(xmid, (char *)&value, STRING_LEN);
if (_value && _attribute)
{
if (!xmlAttributeCompareString(xmid, _attribute, _value))
@ -228,9 +231,9 @@ void walk_the_tree(size_t num, void *xid, char *tree)
{
if (xmlNodeGetPos(xid, xmid, _element, i) != 0)
{
char nodename[64];
char nodename[NODE_NAME_LEN];
xmlNodeCopyName(xmid, (char *)&nodename, 64);
xmlNodeCopyName(xmid, (char *)&nodename, NODE_NAME_LEN);
if (xmlCompareString(xmid, _value) == 0)
{
printf("%s: <%s>%s</%s>\n",
@ -242,22 +245,22 @@ void walk_the_tree(size_t num, void *xid, char *tree)
}
else if (xmid && _element)
{
char parentname[64];
char parentname[NODE_NAME_LEN];
xmlNodeCopyName(xid, (char *)&parentname, 64);
xmlNodeCopyName(xid, (char *)&parentname, NODE_NAME_LEN);
no_elements = xmlNodeGetNum(xmid, _element);
for (i=0; i<no_elements; i++)
{
if (xmlNodeGetPos(xid, xmid, _element, i) != 0)
{
char nodename[64];
char nodename[NODE_NAME_LEN];
xmlNodeCopyName(xmid, (char *)&nodename, 64);
if (strncasecmp((char *)&nodename, _element, 64) == 0)
xmlNodeCopyName(xmid, (char *)&nodename, NODE_NAME_LEN);
if (!strncasecmp((char*)&nodename, _element, NODE_NAME_LEN))
{
char value[64];
xmlCopyString(xmid, (char *)&value, 64);
char value[NODE_NAME_LEN];
xmlCopyString(xmid, (char *)&value, NODE_NAME_LEN);
printf("%s: <%s> <%s>%s</%s> </%s>\n",
_filenames[num], parentname, nodename, value,
nodename, parentname);
@ -319,7 +322,7 @@ void grep_file(unsigned num)
r = xmlErrorGetNo(xrid, 0);
if (r)
{
if (r == XML_ELEMENT_NOT_FOUND)
if (r)
{
size_t n = xmlErrorGetLineNo(xrid, 0);
char *s = xmlErrorGetString(xrid, 1); /* clear the error */