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

find_encoding("UTF-16BE")->encode("abc") does not NUL-terminate

Thread Previous | Thread Next
From:
Gisle Aas
Date:
October 7, 2003 06:29
Subject:
find_encoding("UTF-16BE")->encode("abc") does not NUL-terminate
Message ID:
lrsmm55g8p.fsf_-_@caliper.activestate.com
I had a bug report on the MIME::Base64 module because it kind of
depends on the strings passed to its encode() to be NUL-terminated.
This is not always the case for the strings produced by the Encode
module.  This program demonstrates:

    #!perl -w

    use Encode qw(encode find_encoding);
    use Devel::Peek qw(Dump);

    Dump(encode("UTF-16BE", "abc"));
    Dump(find_encoding("UTF-16BE")->encode("abc"));

With perl-5.8.1 this prints:

    SV = PV(0x819f878) at 0x811f434
      REFCNT = 1
      FLAGS = (TEMP,POK,pPOK)
      PV = 0x8189060 "\0a\0b\0c"\0
      CUR = 6
      LEN = 7
    SV = PV(0x819f878) at 0x811f458
      REFCNT = 1
      FLAGS = (TEMP,POK,pPOK)
      PV = 0x8194fb0 "\0a\0b\0c"
      CUR = 6
      LEN = 6

Note that the first form does the right thing while the second does not.

Regards,
Gisle

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