Re: [xml] utf-8 related problems I think



Its hard to tell exactly what is happening from the short code snippet,
but it seems you've made a stack pointer faux pas. 

The four lines you mentioned are all in a function and the value of utf8
is passed outside of that function (as you indicated) then it points to
an invalid location after the function returns.

Commentary on the four lines:

xmlChar * utf8;    /* Okay, better to initialize to zero */
xmlChar tmp[200]; /* Stack allocated buffer, invalid after function exits */
sprintf(tmp,"%s_%d", someString, someInt); 
                  /* careful that someString isn't > 200 chars */
utf8 = &tmp[0];   /* utf8 points to invalid memory after function exit */

Hope this helps.

Reid.

On Thu, 2004-01-08 at 19:41, Nick Torenvliet wrote:
I am having problems with the following code

xmlChar * utf8;   
xmlChar tmp[200]; 
sprintf(tmp,"%s_%d",someString, someInt); 
utf8 = &tmp[0]; 

everything here works, but later in another function I build an xml
document and write it to a flat file.  

I go on to add utf8 as one of the children of a node.
It all compiles fine but during run-time I get the following errors.

xmlEncodeEntitiesReentrant : input not UTF-8
xmlEncodeEntitiesReentrant : char out of range

It was all working until I changed something much simpler, to the four
lines you see above.  Can anyone see whats wrong here?

Nick

_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
xml gnome org
http://mail.gnome.org/mailman/listinfo/xml


_______________________
Reid Spencer
President & CTO
eXtensible Systems, Inc.
rspencer x10sys com

Attachment: signature.asc
Description: This is a digitally signed message part



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