Integrate with perlio;
[p5sagit/p5-mst-13.2.git] / ext / Encode / Encode.xs
index ba7935e..37d8aac 100644 (file)
@@ -366,7 +366,7 @@ PerlIO_funcs PerlIO_encode = {
 #endif /* encode layer */
 
 void
-Encode_Define(pTHX_ encode_t *enc)
+Encode_XSEncoding(pTHX_ encode_t *enc)
 {
  dSP;
  HV *stash = gv_stashpv("Encode::XS", TRUE);
@@ -409,10 +409,12 @@ encode_method(pTHX_ encode_t *enc, encpage_t *dir, SV *src, int check)
       {
        case ENCODE_NOSPACE:
         {
-         STRLEN need = (slen) ? (SvLEN(dst)*SvCUR(src)/slen) : (dlen + UTF8_MAXLEN);
-         if (need <= SvLEN(dst))
-          need += UTF8_MAXLEN;
+         STRLEN need = dlen + UTF8_MAXLEN * 128; /* 128 is too big or small? */
          d = (U8 *) SvGROW(dst, need);
+         if (dlen >= SvLEN(dst))
+          {
+           Perl_croak(aTHX_ "Destination couldn't be grown (the need may be miscalculated).");
+          }
          dlen = SvLEN(dst);
          slen = SvCUR(src);
          break;