This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add a new macro SvVSTRING_mg that returns vstring magic, if any.
[perl5.git] / pp_sys.c
index fdc9937..a111f1e 100644 (file)
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -1867,7 +1867,7 @@ PP(pp_send)
                    /* Don't call sv_len_utf8 again because it will call magic
                       or overloading a second time, and we might get back a
                       different result.  */
-                   blen_chars = utf8_length(buffer, buffer + blen);
+                   blen_chars = utf8_length((U8*)buffer, (U8*)buffer + blen);
                } else {
                    /* It's safe, and it may well be cached.  */
                    blen_chars = sv_len_utf8(bufsv);
@@ -1885,18 +1885,24 @@ PP(pp_send)
 #else
            length = (Size_t)SvIVx(*++MARK);
 #endif
-           if ((SSize_t)length < 0)
+           if ((SSize_t)length < 0) {
+               Safefree(tmpbuf);
                DIE(aTHX_ "Negative length");
+           }
        }
 
        if (MARK < SP) {
            offset = SvIVx(*++MARK);
            if (offset < 0) {
-               if (-offset > (IV)blen_chars)
+               if (-offset > (IV)blen_chars) {
+                   Safefree(tmpbuf);
                    DIE(aTHX_ "Offset outside string");
+               }
                offset += blen_chars;
-           } else if (offset >= (IV)blen_chars && blen_chars > 0)
+           } else if (offset >= (IV)blen_chars && blen_chars > 0) {
+               Safefree(tmpbuf);
                DIE(aTHX_ "Offset outside string");
+           }
        } else
            offset = 0;
        if (length > blen_chars - offset)
@@ -1959,14 +1965,15 @@ PP(pp_send)
     else
        DIE(aTHX_ PL_no_sock_func, "send");
 #endif
-    if (tmpbuf)
-       Safefree(tmpbuf);
 
     if (retval < 0)
        goto say_undef;
     SP = ORIGMARK;
     if (doing_utf8)
         retval = utf8_length((U8*)buffer, (U8*)buffer + retval);
+
+    if (tmpbuf)
+       Safefree(tmpbuf);
 #if Size_t_size > IVSIZE
     PUSHn(retval);
 #else
@@ -1975,6 +1982,8 @@ PP(pp_send)
     RETURN;
 
   say_undef:
+    if (tmpbuf)
+       Safefree(tmpbuf);
     SP = ORIGMARK;
     RETPUSHUNDEF;
 }
@@ -4638,7 +4647,7 @@ PP(pp_ghostent)
 
     if (hent) {
        PUSHs(sv_2mortal(newSVpv((char*)hent->h_name, 0)));
-       PUSHs(S_space_join_names_mortal(aTHX_ hent->h_aliases));
+       PUSHs(space_join_names_mortal(hent->h_aliases));
        PUSHs(sv_2mortal(newSViv((IV)hent->h_addrtype)));
        len = hent->h_length;
        PUSHs(sv_2mortal(newSViv((IV)len)));
@@ -4721,7 +4730,7 @@ PP(pp_gnetent)
 
     if (nent) {
        PUSHs(sv_2mortal(newSVpv(nent->n_name, 0)));
-       PUSHs(S_space_join_names_mortal(aTHX_ nent->n_aliases));
+       PUSHs(space_join_names_mortal(nent->n_aliases));
        PUSHs(sv_2mortal(newSViv((IV)nent->n_addrtype)));
        PUSHs(sv_2mortal(newSViv((IV)nent->n_net)));
     }
@@ -4782,7 +4791,7 @@ PP(pp_gprotoent)
 
     if (pent) {
        PUSHs(sv_2mortal(newSVpv(pent->p_name, 0)));
-       PUSHs(S_space_join_names_mortal(aTHX_ pent->p_aliases));
+       PUSHs(space_join_names_mortal(pent->p_aliases));
        PUSHs(sv_2mortal(newSViv((IV)pent->p_proto)));
     }
 
@@ -4852,7 +4861,7 @@ PP(pp_gservent)
 
     if (sent) {
        PUSHs(sv_2mortal(newSVpv(sent->s_name, 0)));
-       PUSHs(S_space_join_names_mortal(aTHX_ sent->s_aliases));
+       PUSHs(space_join_names_mortal(sent->s_aliases));
 #ifdef HAS_NTOHS
        PUSHs(sv_2mortal(newSViv((IV)PerlSock_ntohs(sent->s_port))));
 #else
@@ -5269,7 +5278,7 @@ PP(pp_ggrent)
         * but the gr_mem is poisonous anyway.
         * So yes, you cannot get the list of group
         * members if building multithreaded in UNICOS/mk. */
-       PUSHs(S_space_join_names_mortal(aTHX_ grent->gr_mem));
+       PUSHs(space_join_names_mortal(grent->gr_mem));
 #endif
     }