On Sunday 22 May 2005 19:18, Torsten Foertsch wrote:
> Hi,
>
> there is something wrong with APR::Base64.
>
> [EMAIL PROTECTED]:~> perl -MAPR::Base64 -MData::Dumper -e 
> '$x=APR::Base64::encode( "x"
> ); print "$x\n".Dumper( [split "", $x] ), "length=".length($x)."\n";' eA==
> $VAR1 = [
>           'e',
>           'A',
>           '=',
>           '=',
>           ''
>         ];
> length=5
> [EMAIL PROTECTED]:~> perl -MAPR::Base64 -MData::Dumper -e 
> '$x=APR::Base64::encode(
> "xxx" ); print "$x\n".Dumper( [split "", $x] ), "length=".length($x)."\n";'
> eHh4
> $VAR1 = [
>           'e',
>           'H',
>           'h',
>           '4',
>           ''
>         ];
> length=5
>
> In both cases length should be 4 and split("",$x) should return (qw(e a =
> =)).

The problem is apr_base64_encode_len() returns the length including the 
trailing \0 required to hold the encoded string.

This patch cures the problem:

========================================================================
--- xs/APR/Base64/APR__Base64.h 2005-04-26 20:58:34.000000000 +0200
+++ xs/APR/Base64/APR__Base64.h 2005-05-23 22:05:53.416525123 +0200
@@ -18,9 +18,9 @@
     STRLEN len;
     int encoded_len;
     char *data = SvPV(arg, len);
-    mpxs_sv_grow(sv, apr_base64_encode_len(len));
+    mpxs_sv_grow(sv, apr_base64_encode_len(len)-1);
     encoded_len = apr_base64_encode_binary(SvPVX(sv), data, len);
-    mpxs_sv_cur_set(sv, encoded_len);
+    mpxs_sv_cur_set(sv, encoded_len-1);
 }

 static MP_INLINE void mpxs_apr_base64_decode(pTHX_ SV *sv, SV *arg)
========================================================================

but now the APR::Base64::encode_len test fails because it calls simply 
apr_base64_encode_len().

To cure that a new function needs to be introduced in 
xs/APR/Base64/APR__Base64.h ...

I'd do that but I don't know what to call instead of mpxs_sv_cur_set() if I 
want to set an IV.

Torsten

Attachment: pgpzBnNNIkCJ8.pgp
Description: PGP signature

Reply via email to