develooper Front page | perl.perl5.porters | Postings from October 2003

NUL termination - was Re: find_encoding("UTF-16BE")->encode("abc") does not NUL-terminate

Thread Previous | Thread Next
From:
Nick Ing-Simmons
Date:
October 8, 2003 02:03
Subject:
NUL termination - was Re: find_encoding("UTF-16BE")->encode("abc") does not NUL-terminate
Message ID:
20031008090241.2598.4@llama.elixent.com
SADAHIRO Tomoyuki <bqw10602@nifty.com> writes:
>
>IIRC, SvCUR() returns length w/o \0 and SvGROW() needs +1 for \0.
>(sorry I did not rebuilt Encode, please test it)
>

>--- Unicode.xs~	Tue Sep 02 22:39:28 2003
>+++ Unicode.xs	Wed Oct 08 00:34:06 2003
>@@ -54,7 +54,7 @@
> void
> enc_pack(pTHX_ SV *result,STRLEN size,U8 endian,UV value)
> {
>-    U8 *d = (U8 *)SvGROW(result,SvCUR(result)+size);
>+    U8 *d = (U8 *)SvGROW(result,SvCUR(result)+size+1);
>     switch(endian) {
>     case 'v':
>     case 'V':

I could make a case that if someone calls SvPV_nolen(sv) 
then they want the NUL termination so we could expand 
that as :

      SvGROW(sv,SvCUR(sv)+1)

The SvGROW thing is what tend to use, but saddly it doesn't do 
PV-ization.





>
>Regards,
>SADAHIRO Tomoyuki


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About