1
0
Fork 0

Fix a bug in xmlGetString and honour the index attribtute 'n'

This commit is contained in:
ehofman 2009-06-17 07:10:37 +00:00 committed by Tim Moore
parent 783fa8dd7d
commit 84221ac794
2 changed files with 18 additions and 4 deletions

View file

@ -4,7 +4,7 @@
#include "xml.h" #include "xml.h"
void print_xml(void *, char *, int); void print_xml(void *, char *, unsigned int);
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
@ -47,7 +47,7 @@ int main(int argc, char **argv)
} }
} }
void print_xml(void *id, char *name, int len) void print_xml(void *id, char *name, unsigned int len)
{ {
void *xid = xmlMarkId(id); void *xid = xmlMarkId(id);
unsigned int i, num; unsigned int i, num;
@ -72,8 +72,21 @@ void print_xml(void *id, char *name, int len)
{ {
if (xmlNodeGetPos(id, xid, "*", i) != 0) if (xmlNodeGetPos(id, xid, "*", i) != 0)
{ {
int res, i = 4096 - len; unsigned int res, i = 4096 - len;
res = xmlNodeCopyName(xid, (char *)&name[len], i); res = xmlNodeCopyName(xid, (char *)&name[len], i);
if (res)
{
unsigned int index = xmlAttributeGetInt(xid, "n");
if (index)
{
unsigned int pos = len+res;
name[pos++] = '[';
i = snprintf((char *)&name[pos], 4096-pos, "%i", index);
name[pos+i] = ']';
res += i+2;
}
}
print_xml(xid, name, len+res); print_xml(xid, name, len+res);
} }
else printf("error\n"); else printf("error\n");

View file

@ -465,10 +465,11 @@ xmlGetString(const void *id)
char *ps; char *ps;
ps = xid->start; ps = xid->start;
len = xid->len; len = xid->len-1;
__xmlPrepareData(&ps, &len); __xmlPrepareData(&ps, &len);
if (len) if (len)
{ {
len++;
str = malloc(len+1); str = malloc(len+1);
if (str) if (str)
{ {