You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Stefan Voelkel <st...@millenux.com> on 2002/01/04 10:18:31 UTC
Re: Handling "white space" in element value
hi,
> main
> {
> char foo[BUF_SIZE];
> strcpy(foo, textNode.getNodeValue().transcode());
^^^^^^^^^^^^^^ generating memory hole here
> trim (foo);
> }
from the DOM_Strin.transcode() doc:
-------------------
char * DOMString::transcode ( ) const
Returns a copy of the string, transcoded to the local code page.
The caller owns the (char *) string that is returned, and is responsible for deleting it.
Returns:
A pointer to a newly allocated buffer of char elements, which represents the original string, but in the local encoding.
-------------------
regards
stefan
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
Re: Handling "white space" in element value
Posted by Stefan Voelkel <st...@millenux.com>.
> So, u cannot do:
>
> {
> ...
> char* foo = strstr(nodeAux.getNodeValue().transcode(),
> SEARCHSTRING);
> ...
> }
> without dumping memory, don't u?
>
no you can not do this. from DOMString.cpp:
----------------------
char* retP = new char[charsNeeded + 1];
[...]
// Cap it off and return it
retP[charsNeeded] = 0;
return retP;
}
----------------------
so to free the (temporary) space you should do
char *foo = nodeAux.getNodeValue().transcode();
delete [] cp;
and the use of new char[] forbids us to use
auto_ptr<char> foo(nodeAux.getNodeValue().transcode());
because auto_ptr<> does use
delete _Tp;
instead of the needed
delete [] _Tp;
and inheriting from STL's is (mostly) a bad idea (perhaps not in the auto_ptr<> case).
one could write its own array enabled auto_ptr<> perhaps :).
stefan
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
Re: Handling "white space" in element value
Posted by Jorge Pozo Ramirez <j....@externo.mju.es>.
So, u cannot do:
{
...
char* foo = strstr(nodeAux.getNodeValue().transcode(),
SEARCHSTRING);
...
}
without dumping memory, don't u?
I think this is a bit messy, since many times I'll use the transcoded string
only once, and there is no need of getting a permanent pointer for further
use.
Isn't the char buffer returned by transcode() deleted when it comes out
of scope?, (like char arrays do).
Jorge.
> hi,
>
> > main
> > {
> > char foo[BUF_SIZE];
> > strcpy(foo, textNode.getNodeValue().transcode());
>
> ^^^^^^^^^^^^^^ generating memory hole here
>
> > trim (foo);
> > }
>
> from the DOM_Strin.transcode() doc:
>
> -------------------
>
> char * DOMString::transcode ( ) const
>
> Returns a copy of the string, transcoded to the local code page.
>
> The caller owns the (char *) string that is returned, and is responsible
for deleting it.
>
> Returns:
> A pointer to a newly allocated buffer of char elements, which represents
the original string, but in the local encoding.
>
> -------------------
>
> regards
> stefan
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
>
>
>
> ****************************************************************
> Este mensaje ha sido analizado con una herramienta
> de deteccion de virus para su seguridad.
> Ministerio de Justicia
> ***************************************************************
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org