Alright, I checked it out in GDB to witness it myself. I am glad you saw it
because it would be a really subtle bug that would only show up rarely.

The fixed version is posted at:
http://ultrasparcy.mhcomputing.net/~mhall/validator.zip

Regards,
Matt

-----Original Message-----
From: Axel Weiß [mailto:[EMAIL PROTECTED]
Sent: Monday, May 23, 2005 10:31 AM
To: [email protected]
Subject: Re: Handling of schemaLocation attribute


[EMAIL PROTECTED] wrote:
> // widen function
> // Converts ASCII std::string to XMLCh array.
> // NOTE: Caller must delete XMLCh array when finished with it.
> XMLCh* widen(const string& src)
> {
>     // Allocate buffer.
>     XMLCh* dest = new XMLCh[src.length() + 1];
>
>     // Copy from string to buffer.
>     string::size_type i;
>     for (i=0; i < src.length(); ++i)
>         dest[i]=(XMLCh)src[i];
>
>     // Add NULL byte.
>     dest[i+1]=0;
>
>     // Return const pointer to array.
>     return dest;
> }

Hi Matthew,

pay attention! This function casually will crash!

Variable dest points to an array of src.length()+1 elements. After the 
for-loop has finished, i has the value src.length(), and with the next 
statement you access dest[src.length()+1], which is behind the allocated 
array.

In order to explicitly add a NULL byte, you should say
        dest[i] = 0;

Cheers,
                        Axel

-- 
Humboldt-Universität zu Berlin
Institut für Informatik
Signalverarbeitung und Mustererkennung
Dipl.-Inf. Axel Weiß
Rudower Chaussee 25
12489 Berlin-Adlershof
+49-30-2093-3050
** www.freesp.de **

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
___________________________________________________________________
The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.


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

Reply via email to