Commit 39c7d71a authored by Daniel Veillard's avatar Daniel Veillard

Jumbo patch, resync of W3C/Gnome CVS trees:

- uri.c tree.c SAX.c parser.c entities.c debugXML.c: finished
  the cleanup of the computation of URI references when seeking
  external entities. The URI reference string and the resulting
  URI are both stored now.
- parser.c HTMLparser.c valid.c nanoftp.c nanohttp.c xpath.c:
  large s(n)printf checks and cleanup from Denis Barbier
  <barbier@imacs.polytechnique.fr>
- xmlversion.h.in tree.h: couple of SGML declarations for a
  possible docbook module.
- result/VC/ : a couple of test output changed due to the change
  of the entities URI
Daniel
parent b513f5a0
Sun Sep 10 17:53:48 CEST 2000 Daniel Veillard <Daniel.Veillard@w3.org>
* uri.c tree.c SAX.c parser.c entities.c debugXML.c: finished
the cleanup of the computation of URI references when seeking
external entities. The URI reference string and the resulting
URI are both stored now.
* parser.c HTMLparser.c valid.c nanoftp.c nanohttp.c xpath.c:
large s(n)printf checks and cleanup from Denis Barbier
<barbier@imacs.polytechnique.fr>
* xmlversion.h.in tree.h: couple of SGML declarations for a
possible docbook module.
* result/VC/ : a couple of test output changed due to the change
of the entities URI
Sun Sep 10 15:59:58 CEST 2000 Daniel Veillard <Daniel.Veillard@w3.org> Sun Sep 10 15:59:58 CEST 2000 Daniel Veillard <Daniel.Veillard@w3.org>
* parser.h: added a _private field for linking user's data * parser.h: added a _private field for linking user's data
......
...@@ -630,7 +630,7 @@ htmlTagLookup(const xmlChar *tag) { ...@@ -630,7 +630,7 @@ htmlTagLookup(const xmlChar *tag) {
int int
htmlCheckAutoClose(const xmlChar *newtag, const xmlChar *oldtag) { htmlCheckAutoClose(const xmlChar *newtag, const xmlChar *oldtag) {
int i, index; int i, index;
char **close; char **close = NULL;
if (htmlStartCloseIndexinitialized == 0) htmlInitAutoClose(); if (htmlStartCloseIndexinitialized == 0) htmlInitAutoClose();
...@@ -3535,6 +3535,10 @@ htmlInitParserCtxt(htmlParserCtxtPtr ctxt) ...@@ -3535,6 +3535,10 @@ htmlInitParserCtxt(htmlParserCtxtPtr ctxt)
xmlMalloc(5 * sizeof(htmlParserInputPtr)); xmlMalloc(5 * sizeof(htmlParserInputPtr));
if (ctxt->inputTab == NULL) { if (ctxt->inputTab == NULL) {
fprintf(stderr, "htmlInitParserCtxt: out of memory\n"); fprintf(stderr, "htmlInitParserCtxt: out of memory\n");
ctxt->inputNr = 0;
ctxt->inputMax = 0;
ctxt->input = NULL;
return;
} }
ctxt->inputNr = 0; ctxt->inputNr = 0;
ctxt->inputMax = 5; ctxt->inputMax = 5;
...@@ -3546,12 +3550,35 @@ htmlInitParserCtxt(htmlParserCtxtPtr ctxt) ...@@ -3546,12 +3550,35 @@ htmlInitParserCtxt(htmlParserCtxtPtr ctxt)
/* Allocate the Node stack */ /* Allocate the Node stack */
ctxt->nodeTab = (htmlNodePtr *) xmlMalloc(10 * sizeof(htmlNodePtr)); ctxt->nodeTab = (htmlNodePtr *) xmlMalloc(10 * sizeof(htmlNodePtr));
if (ctxt->nodeTab == NULL) {
fprintf(stderr, "htmlInitParserCtxt: out of memory\n");
ctxt->nodeNr = 0;
ctxt->nodeMax = 0;
ctxt->node = NULL;
ctxt->inputNr = 0;
ctxt->inputMax = 0;
ctxt->input = NULL;
return;
}
ctxt->nodeNr = 0; ctxt->nodeNr = 0;
ctxt->nodeMax = 10; ctxt->nodeMax = 10;
ctxt->node = NULL; ctxt->node = NULL;
/* Allocate the Name stack */ /* Allocate the Name stack */
ctxt->nameTab = (xmlChar **) xmlMalloc(10 * sizeof(xmlChar *)); ctxt->nameTab = (xmlChar **) xmlMalloc(10 * sizeof(xmlChar *));
if (ctxt->nameTab == NULL) {
fprintf(stderr, "htmlInitParserCtxt: out of memory\n");
ctxt->nameNr = 0;
ctxt->nameMax = 10;
ctxt->name = NULL;
ctxt->nodeNr = 0;
ctxt->nodeMax = 0;
ctxt->node = NULL;
ctxt->inputNr = 0;
ctxt->inputMax = 0;
ctxt->input = NULL;
return;
}
ctxt->nameNr = 0; ctxt->nameNr = 0;
ctxt->nameMax = 10; ctxt->nameMax = 10;
ctxt->name = NULL; ctxt->name = NULL;
......
...@@ -181,12 +181,13 @@ htmlSetMetaEncoding(htmlDocPtr doc, const xmlChar *encoding) { ...@@ -181,12 +181,13 @@ htmlSetMetaEncoding(htmlDocPtr doc, const xmlChar *encoding) {
return(-1); return(-1);
if (encoding != NULL) { if (encoding != NULL) {
#ifndef HAVE_SNPRINTF #ifdef HAVE_SNPRINTF
snprintf(newcontent, sizeof(newcontent), "text/html; charset=%s",
encoding);
#else
sprintf(newcontent, "text/html; charset=%s", encoding); sprintf(newcontent, "text/html; charset=%s", encoding);
#else /* HAVE_SNPRINTF */ #endif
snprintf(newcontent, 99, "text/html; charset=%s", encoding); newcontent[sizeof(newcontent) - 1] = 0;
#endif /* HAVE_SNPRINTF */
newcontent[99] = 0;
} }
cur = doc->children; cur = doc->children;
......
...@@ -311,13 +311,26 @@ xmlParserInputPtr ...@@ -311,13 +311,26 @@ xmlParserInputPtr
resolveEntity(void *ctx, const xmlChar *publicId, const xmlChar *systemId) resolveEntity(void *ctx, const xmlChar *publicId, const xmlChar *systemId)
{ {
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
xmlParserInputPtr ret;
char *URI;
const char *base = NULL;
if (ctxt->input != NULL)
base = ctxt->input->filename;
if (base == NULL)
base = ctxt->directory;
URI = xmlBuildURI(systemId, base);
#ifdef DEBUG_SAX #ifdef DEBUG_SAX
fprintf(stderr, "SAX.resolveEntity(%s, %s)\n", publicId, systemId); fprintf(stderr, "SAX.resolveEntity(%s, %s)\n", publicId, systemId);
#endif #endif
return(xmlLoadExternalEntity((const char *) systemId, ret = xmlLoadExternalEntity((const char *) URI,
(const char *) publicId, ctxt)); (const char *) publicId, ctxt);
if (URI != NULL)
xmlFree(URI);
return(ret);
} }
/** /**
...@@ -409,6 +422,18 @@ entityDecl(void *ctx, const xmlChar *name, int type, ...@@ -409,6 +422,18 @@ entityDecl(void *ctx, const xmlChar *name, int type,
(ctxt->sax != NULL) && (ctxt->sax->warning != NULL)) (ctxt->sax != NULL) && (ctxt->sax->warning != NULL))
ctxt->sax->warning(ctxt, ctxt->sax->warning(ctxt,
"Entity(%s) already defined in the internal subset\n", name); "Entity(%s) already defined in the internal subset\n", name);
if ((ent != NULL) && (ent->URI == NULL) && (systemId != NULL)) {
char *URI;
const char *base = NULL;
if (ctxt->input != NULL)
base = ctxt->input->filename;
if (base == NULL)
base = ctxt->directory;
URI = xmlBuildURI(systemId, base);
ent->URI = URI;
}
} else if (ctxt->inSubset == 2) { } else if (ctxt->inSubset == 2) {
ent = xmlAddDtdEntity(ctxt->myDoc, name, type, publicId, ent = xmlAddDtdEntity(ctxt->myDoc, name, type, publicId,
systemId, content); systemId, content);
...@@ -416,6 +441,18 @@ entityDecl(void *ctx, const xmlChar *name, int type, ...@@ -416,6 +441,18 @@ entityDecl(void *ctx, const xmlChar *name, int type,
(ctxt->sax != NULL) && (ctxt->sax->warning != NULL)) (ctxt->sax != NULL) && (ctxt->sax->warning != NULL))
ctxt->sax->warning(ctxt, ctxt->sax->warning(ctxt,
"Entity(%s) already defined in the external subset\n", name); "Entity(%s) already defined in the external subset\n", name);
if ((ent != NULL) && (ent->URI == NULL) && (systemId != NULL)) {
char *URI;
const char *base = NULL;
if (ctxt->input != NULL)
base = ctxt->input->filename;
if (base == NULL)
base = ctxt->directory;
URI = xmlBuildURI(systemId, base);
ent->URI = URI;
}
} else { } else {
if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
ctxt->sax->error(ctxt, ctxt->sax->error(ctxt,
...@@ -1603,3 +1640,73 @@ htmlDefaultSAXHandlerInit(void) ...@@ -1603,3 +1640,73 @@ htmlDefaultSAXHandlerInit(void)
htmlDefaultSAXHandler.error = xmlParserError; htmlDefaultSAXHandler.error = xmlParserError;
htmlDefaultSAXHandler.fatalError = xmlParserError; htmlDefaultSAXHandler.fatalError = xmlParserError;
} }
/*
* Default handler for HTML, builds the DOM tree
*/
xmlSAXHandler sgmlDefaultSAXHandler = {
internalSubset,
NULL,
NULL,
NULL,
NULL,
getEntity,
NULL,
NULL,
NULL,
NULL,
NULL,
setDocumentLocator,
startDocument,
endDocument,
startElement,
endElement,
NULL,
characters,
ignorableWhitespace,
NULL,
comment,
xmlParserWarning,
xmlParserError,
xmlParserError,
getParameterEntity,
NULL,
NULL,
};
/**
* sgmlDefaultSAXHandlerInit:
*
* Initialize the default SAX handler
*/
void
sgmlDefaultSAXHandlerInit(void)
{
sgmlDefaultSAXHandler.internalSubset = internalSubset;
sgmlDefaultSAXHandler.externalSubset = NULL;
sgmlDefaultSAXHandler.isStandalone = NULL;
sgmlDefaultSAXHandler.hasInternalSubset = NULL;
sgmlDefaultSAXHandler.hasExternalSubset = NULL;
sgmlDefaultSAXHandler.resolveEntity = NULL;
sgmlDefaultSAXHandler.getEntity = getEntity;
sgmlDefaultSAXHandler.getParameterEntity = NULL;
sgmlDefaultSAXHandler.entityDecl = NULL;
sgmlDefaultSAXHandler.attributeDecl = NULL;
sgmlDefaultSAXHandler.elementDecl = NULL;
sgmlDefaultSAXHandler.notationDecl = NULL;
sgmlDefaultSAXHandler.unparsedEntityDecl = NULL;
sgmlDefaultSAXHandler.setDocumentLocator = setDocumentLocator;
sgmlDefaultSAXHandler.startDocument = startDocument;
sgmlDefaultSAXHandler.endDocument = endDocument;
sgmlDefaultSAXHandler.startElement = startElement;
sgmlDefaultSAXHandler.endElement = endElement;
sgmlDefaultSAXHandler.reference = NULL;
sgmlDefaultSAXHandler.characters = characters;
sgmlDefaultSAXHandler.cdataBlock = NULL;
sgmlDefaultSAXHandler.ignorableWhitespace = ignorableWhitespace;
sgmlDefaultSAXHandler.processingInstruction = NULL;
sgmlDefaultSAXHandler.comment = comment;
sgmlDefaultSAXHandler.warning = xmlParserWarning;
sgmlDefaultSAXHandler.error = xmlParserError;
sgmlDefaultSAXHandler.fatalError = xmlParserError;
}
...@@ -109,6 +109,7 @@ void cdataBlock (void *ctx, ...@@ -109,6 +109,7 @@ void cdataBlock (void *ctx,
void xmlDefaultSAXHandlerInit (void); void xmlDefaultSAXHandlerInit (void);
void htmlDefaultSAXHandlerInit (void); void htmlDefaultSAXHandlerInit (void);
void sgmlDefaultSAXHandlerInit (void);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -249,11 +249,11 @@ void xmlDebugDumpElemDecl(FILE *output, xmlElementPtr elem, int depth) { ...@@ -249,11 +249,11 @@ void xmlDebugDumpElemDecl(FILE *output, xmlElementPtr elem, int depth) {
break; break;
} }
if (elem->content != NULL) { if (elem->content != NULL) {
char buf[1001]; char buf[5001];
buf[0] = 0; buf[0] = 0;
xmlSprintfElementContent(buf, elem->content, 1); xmlSprintfElementContent(buf, elem->content, 1);
buf[1000] = 0; buf[5000] = 0;
fprintf(output, "%s", buf); fprintf(output, "%s", buf);
} }
printf("\n"); printf("\n");
...@@ -325,15 +325,19 @@ void xmlDebugDumpEntityDecl(FILE *output, xmlEntityPtr ent, int depth) { ...@@ -325,15 +325,19 @@ void xmlDebugDumpEntityDecl(FILE *output, xmlEntityPtr ent, int depth) {
} }
if (ent->ExternalID) { if (ent->ExternalID) {
fprintf(output, shift); fprintf(output, shift);
fprintf(output, "ExternalID=%s\n", ent->ExternalID); fprintf(output, " ExternalID=%s\n", ent->ExternalID);
} }
if (ent->SystemID) { if (ent->SystemID) {
fprintf(output, shift); fprintf(output, shift);
fprintf(output, "SystemID=%s\n", ent->SystemID); fprintf(output, " SystemID=%s\n", ent->SystemID);
}
if (ent->URI != NULL) {
fprintf(output, shift);
fprintf(output, " URI=%s\n", ent->URI);
} }
if (ent->content) { if (ent->content) {
fprintf(output, shift); fprintf(output, shift);
fprintf(output, "content="); fprintf(output, " content=");
xmlDebugDumpString(output, ent->content); xmlDebugDumpString(output, ent->content);
fprintf(output, "\n"); fprintf(output, "\n");
} }
...@@ -434,6 +438,10 @@ void xmlDebugDumpEntity(FILE *output, xmlEntityPtr ent, int depth) { ...@@ -434,6 +438,10 @@ void xmlDebugDumpEntity(FILE *output, xmlEntityPtr ent, int depth) {
fprintf(output, shift); fprintf(output, shift);
fprintf(output, "SystemID=%s\n", ent->SystemID); fprintf(output, "SystemID=%s\n", ent->SystemID);
} }
if (ent->URI) {
fprintf(output, shift);
fprintf(output, "URI=%s\n", ent->URI);
}
if (ent->content) { if (ent->content) {
fprintf(output, shift); fprintf(output, shift);
fprintf(output, "content="); fprintf(output, "content=");
...@@ -618,7 +626,7 @@ void xmlDebugDumpOneNode(FILE *output, xmlNodePtr node, int depth) { ...@@ -618,7 +626,7 @@ void xmlDebugDumpOneNode(FILE *output, xmlNodePtr node, int depth) {
void xmlDebugDumpNode(FILE *output, xmlNodePtr node, int depth) { void xmlDebugDumpNode(FILE *output, xmlNodePtr node, int depth) {
xmlDebugDumpOneNode(output, node, depth); xmlDebugDumpOneNode(output, node, depth);
if (node->children != NULL) if ((node->children != NULL) && (node->type != XML_ENTITY_REF_NODE))
xmlDebugDumpNodeList(output, node->children, depth + 1); xmlDebugDumpNodeList(output, node->children, depth + 1);
} }
...@@ -695,6 +703,11 @@ void xmlDebugDumpDocumentHead(FILE *output, xmlDocPtr doc) { ...@@ -695,6 +703,11 @@ void xmlDebugDumpDocumentHead(FILE *output, xmlDocPtr doc) {
xmlDebugDumpString(output, doc->encoding); xmlDebugDumpString(output, doc->encoding);
fprintf(output, "\n"); fprintf(output, "\n");
} }
if (doc->URL != NULL) {
fprintf(output, "URL=");
xmlDebugDumpString(output, doc->URL);
fprintf(output, "\n");
}
if (doc->standalone) if (doc->standalone)
fprintf(output, "standalone=true\n"); fprintf(output, "standalone=true\n");
if (doc->oldNs != NULL) if (doc->oldNs != NULL)
...@@ -714,6 +727,47 @@ void xmlDebugDumpDocument(FILE *output, xmlDocPtr doc) { ...@@ -714,6 +727,47 @@ void xmlDebugDumpDocument(FILE *output, xmlDocPtr doc) {
xmlDebugDumpNodeList(output, doc->children, 1); xmlDebugDumpNodeList(output, doc->children, 1);
} }
void xmlDebugDumpDTD(FILE *output, xmlDtdPtr dtd) {
if (dtd == NULL)
return;
if (dtd->type != XML_DTD_NODE) {
fprintf(output, "PBM: not a DTD\n");
return;
}
if (dtd->name != NULL)
fprintf(output, "DTD(%s)", dtd->name);
else
fprintf(output, "DTD");
if (dtd->ExternalID != NULL)
fprintf(output, ", PUBLIC %s", dtd->ExternalID);
if (dtd->SystemID != NULL)
fprintf(output, ", SYSTEM %s", dtd->SystemID);
fprintf(output, "\n");
/*
* Do a bit of checking
*/
if ((dtd->parent != NULL) && (dtd->doc != dtd->parent->doc))
fprintf(output, "PBM: Dtd doc differs from parent's one\n");
if (dtd->prev == NULL) {
if ((dtd->parent != NULL) && (dtd->parent->children != (xmlNodePtr)dtd))
fprintf(output, "PBM: Dtd has no prev and not first of list\n");
} else {
if (dtd->prev->next != (xmlNodePtr) dtd)
fprintf(output, "PBM: Dtd prev->next : back link wrong\n");
}
if (dtd->next == NULL) {
if ((dtd->parent != NULL) && (dtd->parent->last != (xmlNodePtr) dtd))
fprintf(output, "PBM: Dtd has no next and not last of list\n");
} else {
if (dtd->next->prev != (xmlNodePtr) dtd)
fprintf(output, "PBM: Dtd next->prev : forward link wrong\n");
}
if (dtd->children == NULL)
fprintf(output, " DTD is empty\n");
else
xmlDebugDumpNodeList(output, dtd->children, 1);
}
void xmlDebugDumpEntities(FILE *output, xmlDocPtr doc) { void xmlDebugDumpEntities(FILE *output, xmlDocPtr doc) {
int i; int i;
xmlEntityPtr cur; xmlEntityPtr cur;
...@@ -1456,9 +1510,29 @@ xmlShellPwd(xmlShellCtxtPtr ctxt, char *buffer, xmlNodePtr node, ...@@ -1456,9 +1510,29 @@ xmlShellPwd(xmlShellCtxtPtr ctxt, char *buffer, xmlNodePtr node,
next = cur->parent; next = cur->parent;
} }
if (occur == 0) if (occur == 0)
#ifdef HAVE_SNPRINTF
snprintf(buf, sizeof(buf), "%c%s%s", sep, name, buffer);
#else
sprintf(buf, "%c%s%s", sep, name, buffer); sprintf(buf, "%c%s%s", sep, name, buffer);
else #endif
else
#ifdef HAVE_SNPRINTF
snprintf(buf, sizeof(buf), "%c%s[%d]%s",
sep, name, occur, buffer);
#else
sprintf(buf, "%c%s[%d]%s", sep, name, occur, buffer); sprintf(buf, "%c%s[%d]%s", sep, name, occur, buffer);
#endif
buf[sizeof(buf) - 1] = 0;
/*
* This test prevents buffer overflow, because this routine
* is only called by xmlShell, in which the second argument is
* 500 chars long.
* It is a dirty hack before a cleaner solution is found.
* Documentation should mention that the second argument must
* be at least 500 chars long, and could be stripped if too long.
*/
if (strlen(buffer) + strlen(buf) > 499)
break;
strcpy(buffer, buf); strcpy(buffer, buf);
cur = next; cur = next;
} while (cur != NULL); } while (cur != NULL);
...@@ -1516,9 +1590,14 @@ xmlShell(xmlDocPtr doc, char *filename, xmlShellReadlineFunc input, ...@@ -1516,9 +1590,14 @@ xmlShell(xmlDocPtr doc, char *filename, xmlShellReadlineFunc input,
if (ctxt->node == (xmlNodePtr) ctxt->doc) if (ctxt->node == (xmlNodePtr) ctxt->doc)
sprintf(prompt, "%s > ", "/"); sprintf(prompt, "%s > ", "/");
else if (ctxt->node->name) else if (ctxt->node->name)
sprintf(prompt, "%s > ", ctxt->node->name); #ifdef HAVE_SNPRINTF
else snprintf(prompt, sizeof(prompt), "%s > ", ctxt->node->name);
#else
sprintf(buf, "%s > ", ctxt->node->name);
#endif
else
sprintf(prompt, "? > "); sprintf(prompt, "? > ");
prompt[sizeof(prompt) - 1] = 0;
cmdline = ctxt->input(prompt); cmdline = ctxt->input(prompt);
if (cmdline == NULL) break; if (cmdline == NULL) break;
......
...@@ -42,6 +42,8 @@ void xmlDebugDumpDocumentHead(FILE *output, ...@@ -42,6 +42,8 @@ void xmlDebugDumpDocumentHead(FILE *output,
xmlDocPtr doc); xmlDocPtr doc);
void xmlDebugDumpDocument (FILE *output, void xmlDebugDumpDocument (FILE *output,
xmlDocPtr doc); xmlDocPtr doc);
void xmlDebugDumpDTD (FILE *output,
xmlDtdPtr doc);
void xmlDebugDumpEntities (FILE *output, void xmlDebugDumpEntities (FILE *output,
xmlDocPtr doc); xmlDocPtr doc);
void xmlLsOneNode (FILE *output, void xmlLsOneNode (FILE *output,
......
...@@ -76,6 +76,8 @@ void xmlFreeEntity(xmlEntityPtr entity) { ...@@ -76,6 +76,8 @@ void xmlFreeEntity(xmlEntityPtr entity) {
xmlFree((char *) entity->ExternalID); xmlFree((char *) entity->ExternalID);
if (entity->SystemID != NULL) if (entity->SystemID != NULL)
xmlFree((char *) entity->SystemID); xmlFree((char *) entity->SystemID);
if (entity->URI != NULL)
xmlFree((char *) entity->URI);
if (entity->content != NULL) if (entity->content != NULL)
xmlFree((char *) entity->content); xmlFree((char *) entity->content);
if (entity->orig != NULL) if (entity->orig != NULL)
...@@ -198,6 +200,8 @@ xmlAddEntity(xmlEntitiesTablePtr table, const xmlChar *name, int type, ...@@ -198,6 +200,8 @@ xmlAddEntity(xmlEntitiesTablePtr table, const xmlChar *name, int type,
ret->length = 0; ret->length = 0;
ret->content = NULL; ret->content = NULL;
} }
ret->URI = NULL; /* to be computed by the layer knowing
the defining entity */
ret->orig = NULL; ret->orig = NULL;
table->nb_entities++; table->nb_entities++;
...@@ -590,8 +594,6 @@ xmlGetParameterEntity(xmlDocPtr doc, const xmlChar *name) { ...@@ -590,8 +594,6 @@ xmlGetParameterEntity(xmlDocPtr doc, const xmlChar *name) {
xmlEntitiesTablePtr table; xmlEntitiesTablePtr table;
xmlEntityPtr ret; xmlEntityPtr ret;
if (doc == NULL)
return(NULL);
if ((doc->intSubset != NULL) && (doc->intSubset->entities != NULL)) { if ((doc->intSubset != NULL) && (doc->intSubset->entities != NULL)) {
table = (xmlEntitiesTablePtr) doc->intSubset->entities; table = (xmlEntitiesTablePtr) doc->intSubset->entities;
ret = xmlGetEntityFromTable(table, name, 1); ret = xmlGetEntityFromTable(table, name, 1);
...@@ -619,8 +621,6 @@ xmlEntityPtr ...@@ -619,8 +621,6 @@ xmlEntityPtr
xmlGetDtdEntity(xmlDocPtr doc, const xmlChar *name) { xmlGetDtdEntity(xmlDocPtr doc, const xmlChar *name) {
xmlEntitiesTablePtr table; xmlEntitiesTablePtr table;
if (doc == NULL)
return(NULL);
if ((doc->extSubset != NULL) && (doc->extSubset->entities != NULL)) { if ((doc->extSubset != NULL) && (doc->extSubset->entities != NULL)) {
table = (xmlEntitiesTablePtr) doc->extSubset->entities; table = (xmlEntitiesTablePtr) doc->extSubset->entities;
return(xmlGetEntityFromTable(table, name, 0)); return(xmlGetEntityFromTable(table, name, 0));
...@@ -783,11 +783,13 @@ xmlEncodeEntities(xmlDocPtr doc, const xmlChar *input) { ...@@ -783,11 +783,13 @@ xmlEncodeEntities(xmlDocPtr doc, const xmlChar *input) {
#ifndef USE_UTF_8 #ifndef USE_UTF_8
} else if ((sizeof(xmlChar) == 1) && (*cur >= 0x80)) { } else if ((sizeof(xmlChar) == 1) && (*cur >= 0x80)) {
char buf[10], *ptr; char buf[10], *ptr;
#ifdef HAVE_SNPRINTF #ifdef HAVE_SNPRINTF
snprintf(buf, 9, "&#%d;", *cur); snprintf(buf, sizeof(buf), "&#%d;", *cur);
#else #else
sprintf(buf, "&#%d;", *cur); sprintf(buf, "&#%d;", *cur);
#endif #endif
buf[sizeof(buf) - 1] = 0;
ptr = buf; ptr = buf;
while (*ptr != 0) *out++ = *ptr++; while (*ptr != 0) *out++ = *ptr++;
#endif #endif
...@@ -795,10 +797,11 @@ xmlEncodeEntities(xmlDocPtr doc, const xmlChar *input) { ...@@ -795,10 +797,11 @@ xmlEncodeEntities(xmlDocPtr doc, const xmlChar *input) {
char buf[10], *ptr; char buf[10], *ptr;
#ifdef HAVE_SNPRINTF #ifdef HAVE_SNPRINTF
snprintf(buf, 9, "&#%d;", *cur); snprintf(buf, sizeof(buf), "&#%d;", *cur);
#else #else
sprintf(buf, "&#%d;", *cur); sprintf(buf, "&#%d;", *cur);
#endif #endif
buf[sizeof(buf) - 1] = 0;
ptr = buf; ptr = buf;
while (*ptr != 0) *out++ = *ptr++; while (*ptr != 0) *out++ = *ptr++;
} }
...@@ -918,9 +921,15 @@ xmlEncodeEntitiesReentrant(xmlDocPtr doc, const xmlChar *input) { ...@@ -918,9 +921,15 @@ xmlEncodeEntitiesReentrant(xmlDocPtr doc, const xmlChar *input) {
} else if (*cur >= 0x80) { } else if (*cur >= 0x80) {
if ((doc->encoding != NULL) || (html)) { if ((doc->encoding != NULL) || (html)) {
/* /*
* TODO !!! * Bjrn Reese <br@sseusa.com> provided the patch
xmlChar xc;
xc = (*cur & 0x3F) << 6;
if (cur[1] != 0) {
xc += *(++cur) & 0x3F;
*out++ = xc;
} else
*/ */
*out++ = *cur; *out++ = *cur;
} else { } else {
/* /*
* We assume we have UTF-8 input. * We assume we have UTF-8 input.
...@@ -933,10 +942,11 @@ xmlEncodeEntitiesReentrant(xmlDocPtr doc, const xmlChar *input) { ...@@ -933,10 +942,11 @@ xmlEncodeEntitiesReentrant(xmlDocPtr doc, const xmlChar *input) {
"xmlEncodeEntitiesReentrant : input not UTF-8\n"); "xmlEncodeEntitiesReentrant : input not UTF-8\n");