Re: [xml] xmlSchemaNewSchema() question



ai2097 said:
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)
 *
  <snip>

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

I think the answer to this question lies in noticing that this
function is declared as 'static', i.e. only used within this module.
A search for references reveals that there is only one, and it uses
a non-NULL value for the parameter.  I would therefore conclude that
at the time the routine was initially written (probably before
dictionaries were added to the library to dramatically improve it's
efficiency) the coder thought that the parameter wouldn't
necessarily be required.  At the present time, however, I would say
it is required (at least at the one place the routine is called), so
the "(optional)" comment should be removed.  I'll remove it the next
time I do a CVS commit :-).

Thanks for your interest, and please continue to let us know
whenever you discover places in the source where the coding doesn't
appear to agree with the comments.

Regards,
Bill



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