as a recovering win32 dev, i'll take a poke :-)

i hope this helps. and i apologize in advance to everybody if i seem
overly pedantic or snippy.

CtrlsValidHeapPointer(pUserData)

generally, this assertion is telling you that you are trying to free() or 
read() from a bogus pointer.

char *attrValC = input.getNodeValue().transcode()

this line makes unwarranted assumptions about pointer quality.  i say
'unwarranted' because if the implication of this code was warranted, you
wouldnt fire the assertion :-).

i havent looked at the api, but i am sure that it isnt guaranteed not to
fail on occasion.

And...it actually allocs the buffer and gives it back to you? man, i hate
that. great way to create mem leaks if the caller is sloppy. i do
recognize why someone might choose to code it that way cause there are
lots of obvious benefits...but....

so assuming that it alloc()'s or new's the buffer, you are good to go. but
if it *fails*, either due to insufficient mem on the heap ( doubtful, but
possible with lotsa leaks :-) ) or due to the data operated on by
transcode() being bad or nonexistent ( likely case ), u now have a NULL
ptr (if it was coded the way i like) or a junk ptr if the callee didnt
explicitly set it to NULL. 

so, you then go off and try to operate on the ptr of unknown quality, and
worse yet, you make doubly sure to work on the ptr of unknown quality :-).

note that the strcpy() will work even if the ptr's shite. but the delete
will barf, which fires your catch, which then retrys the delete....oh ick.

  try {
             strcpy(output,attrValC);
             delete [] attrValC;
     }
     catch (...) {
             delete [] attrValC;
             throw;
     }

now, i agree that you want to avoid a mem leak by making sure that all
path's out of your code free the buffer. but you needed to make sure that
it actually existed in the first place. does the trancode() have any
exceptions to share? if it can toss an exception, it should be in the
try{}. if it doesnt, then we just have yet another example of 'Why C++
Annoys Me'(tm).

actually, this whole problem is actually a fine example thereof :-).
mixing procedural and object idioms can lead to much despair and gnashing
of teeth.

so, assuming that transcode() is coded the way i like it ( i dont know if
it is ) and either sets the ptr to NULL or leaves the ptr ALONE if it
doesnt have anything to attach to it:

char *attrValC = NULL;

attrValC = input.getNodeValue().transcode();

if(NULL == attrValC) return();

a final, tangentially related point: if you are expecting this code to run
on something other than a US Win32 machine than you *really* should avoid
using char! it will *break* on a widechar(UNICODE) Win32 machine ( with
widechar==everything !US ). but that's probably what transcode() expects,
so you probably are stuck.

On Tue, 22 Jan 2002, Xerces Rule wrote:

> Hi.
> 
> Thank you for your answer, Jesse.
> 
> I was reading another thread dealing with this topic:
> http://archive.covalent.net/xml/xerces-c-dev/2000/08/0020.xml
> 
> Manu Heirbaut suggested to use a multithreaded DLL. In VC++,
> I set 'Debug Multithreaded DLL' at Project>Settings>C++>Code
> Generating (Settings for Win32 Debug).
> 
> But I'm still getting the same error.
> 
> NOTES: 
> + I'm trying to develop a DLL.
> + I'm using Xerces-C 1.6.0
> 
> Cheers.
> 
> El Tue, 22 Jan 2002 11:20:26 -0500
>  Jesse Pelton <[EMAIL PROTECTED]> escribi�:
> > See http://xml.apache.org/xerces-c/faq-parse.html#faq-26.
> > 
> > -----Original Message-----
> > From: Xerces Rule [mailto:[EMAIL PROTECTED]]
> > Sent: Tuesday, January 22, 2002 10:59 AM
> > To: [EMAIL PROTECTED]
> > Subject: Debug Assertion Failed
> > 
> > 
> > Hi again.
> > 
> > I succeeded in inserting a function to obtain the text
> > string from a Node:
> > 
> > void myFunciton (DOM_Node input, char *output) {
> >     char *attrValC = input.getNodeValue().transcode();
> >             
> >     try {
> >             strcpy(output,attrValC);                
> >             delete [] attrValC;
> >     }
> >     catch (...) {
> >             delete [] attrValC;
> >             throw;
> >     }
> > }
> > 
> > I've got no problems with the Release Program (VC++6.0 on
> > NT4.0), but when executing the Debug one, I get this pop
> > up
> > error message:
> > *************
> > Debug Assertion Failed
> > Program: dbgheap.c
> > Line: 1044
> > Expression: _CtrlsValidHeapPointer(pUserData)
> > *************
> > 
> > I've been browsing the Internet, and there are more
> > similar
> > cases. I would be extremely obliged if anybody could
> > explain
> > me if this is an Xerces bug, a MS bug or I am to blame.
> > 
> > Regards.
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail:
> > [EMAIL PROTECTED]
> > 
> 
> _______________________________________________________________________
> �Ya conoces eBay, el mayor centro de compra y venta en internet?
> M�viles, port�tiles, pda�s, cd�s, c�maras digitales...
> �Compru�balo t� mismo!
> 
>http://adfarm.mediaplex.com/ad/ck/1185-5550-4234-3?RedirectEnter&partner=34113&loc=http://www.es.ebay.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to