After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 121210 - Varying pointers in SAX2 error reporting callbacks
Varying pointers in SAX2 error reporting callbacks
Status: VERIFIED FIXED
Product: libxml2
Classification: Platform
Component: general
2.5.8
Other Linux
: Normal normal
: ---
Assigned To: William M. Brack
William M. Brack
Depends on:
Blocks:
 
 
Reported: 2003-09-01 21:36 UTC by Dave Beckett
Modified: 2009-08-15 18:40 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Dave Beckett 2003-09-01 21:36:19 UTC
There are two methods in the xmlSAXHandler structure (in parser.h)
for error reporting:
  warningSAXFunc warning;
  errorSAXFunc error;

These callbacks have the following signatures:

  typedef void (*warningSAXFunc) (void *ctx, const char *msg, ...);
  typedef void (*errorSAXFunc) (void *ctx, const char *msg, ...);

where the first argument 'ctx' is the userData field aka
ctxt->userData inside libxml2, or so I thought.

However, it seems that these aren't always called with that;
sometimes they are returned ctxt itself, an xmlParserCtxtPtr.

i.e. depending on the call or the type of error, you get a
different pointer!

I got bitten by this since I was handling an XML error that I had not
had before - failure to find an external entity (which is in xmlIO.c,
see below) - and the error reporting in my application just crashed.

In the latest sources in CVS:

grep 'sax->error(' *.c | grep -v 'ctxt->userData'

SAX2.c:                 ctxt->sax->error(ctxt,
SAX2.c:     ctxt->sax->error(ctxt,
SAX2.c:     ctxt->sax->error(ctxt,
SAX2.c:     ctxt->sax->error(ctxt,
SAX2.c:            ctxt->sax->error(ctxt,
SAX2.c:     ctxt->sax->error(ctxt,
SAX2.c:     ctxt->sax->error(ctxt,
SAX2.c:     ctxt->sax->error(ctxt,
xmlIO.c:            ctxt->sax->error(ctxt,
xmlIO.c:            ctxt->sax->error(ctxt,

grep 'sax->warning(' *.c | grep -v 'ctxt->userData'

SAX2.c:     ctxt->sax->warning(ctxt,
SAX2.c:     ctxt->sax->warning(ctxt,
SAX2.c:     ctxt->sax->warning(ctxt,
SAX2.c:     ctxt->sax->warning(ctxt,
xmlIO.c:            ctxt->sax->warning(ctxt,
xmlIO.c:            ctxt->sax->warning(ctxt,


If you look instead for the sax->error/warning calls with
ctxt->userData, there are hundreds of them.  So I expect the ones
above are the problem.

Since I want to work with installed libxml2s, I'll validate the
returned pointer so I can pick the correct one:

  if(((raptor_parser*)ctx)->magic == RAPTOR_LIBXML_MAGIC)
    rdf_parser=(raptor_parser*)ctx;
  else
    /* ctx is not userData */
    rdf_parser=(raptor_parser*)((xmlParserCtxtPtr)ctx)->userData;

which works.

Dave
Comment 1 William M. Brack 2003-09-06 18:03:44 UTC
Fixed in CVS.  Thanks for your report.
Comment 2 Daniel Veillard 2003-10-21 12:36:31 UTC
This should be fixed in release libxml2-2.6.0,
                                                                     
          
  thanks,
                                                                     
          
Daniel