[xml] xmlSchemaNewSchema() question



I was poking through the (CVS) source for gnome-xml (libxml2) and came
up on this around line 366 in xmlschemas.c:

---
/**
 * xmlSchemaNewSchema:
 * @ctxt:  a schema validation context (optional)
 *
 * Allocate a new Schema structure.
 *
 * Returns the newly allocated structure or NULL in case or error
 */
static xmlSchemaPtr
xmlSchemaNewSchema(xmlSchemaParserCtxtPtr ctxt)
{
    xmlSchemaPtr ret;

    ret = (xmlSchemaPtr) xmlMalloc(sizeof(xmlSchema));
    if (ret == NULL) {
        xmlSchemaPErrMemory(ctxt, "allocating schema", NULL);
        return (NULL);
    }
    memset(ret, 0, sizeof(xmlSchema));
    xmlDictReference(ctxt->dict);
    ret->dict = ctxt->dict;

    return (ret);
}

---

Now, saying `ctxt' is "optional," to me, means that it would be valid
for `ctxt' to be NULL. If this is the case, shouldn't the following
block:

    xmlDictReference(ctxt->dict);
    ret->dict = ctxt->dict;

instead be structured like this:

    if (ctxt) {
        xmlDictReference(ctxt->dict);
        ret->dict = ctxt->dict;
    }

in order to prevent a NULL-pointer dereference/segfault? Or am I simply
misinterpreting the meaning of "optional?"


-- Travis




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]