$foo .= $bar doesn't warn if $foo is undefined, so simplify code.
[p5sagit/p5-mst-13.2.git] / perlio.c
index e796607..0b010b8 100644 (file)
--- a/perlio.c
+++ b/perlio.c
@@ -1182,19 +1182,26 @@ PerlIO_push(pTHX_ PerlIO *f, PERLIO_FUNCS_DECL(*tab), const char *mode, SV *arg)
            goto mismatch;
        }
        /* Real layer with a data area */
-       Newxc(l,tab->size,char,PerlIOl);
-       if (l && f) {
-           Zero(l, tab->size, char);
-           l->next = *f;
-           l->tab = (PerlIO_funcs*) tab;
-           *f = l;
-           PerlIO_debug("PerlIO_push f=%p %s %s %p\n", (void*)f, tab->name,
-                       (mode) ? mode : "(Null)", (void*)arg);
-           if (*l->tab->Pushed &&
-               (*l->tab->Pushed) (aTHX_ f, mode, arg, (PerlIO_funcs*) tab) != 0) {
-               PerlIO_pop(aTHX_ f);
-               return NULL;
+       if (f) {
+           char *temp;
+           Newxz(temp, tab->size, char);
+           l = (PerlIOl*)temp;
+           if (l) {
+               l->next = *f;
+               l->tab = (PerlIO_funcs*) tab;
+               *f = l;
+               PerlIO_debug("PerlIO_push f=%p %s %s %p\n",
+                            (void*)f, tab->name,
+                            (mode) ? mode : "(Null)", (void*)arg);
+               if (*l->tab->Pushed &&
+                   (*l->tab->Pushed)
+                     (aTHX_ f, mode, arg, (PerlIO_funcs*) tab) != 0) {
+                   PerlIO_pop(aTHX_ f);
+                   return NULL;
+               }
            }
+           else
+               return NULL;
        }
     }
     else if (f) {
@@ -2864,7 +2871,6 @@ PerlIOStdio_open(pTHX_ PerlIO_funcs *self, PerlIO_list_t *layers,
 #endif
                stdio = PerlSIO_fopen(path, mode);
                if (stdio) {
-                   PerlIOStdio *s;
                    if (!f) {
                        f = PerlIO_allocate(aTHX);
                    }
@@ -2872,9 +2878,10 @@ PerlIOStdio_open(pTHX_ PerlIO_funcs *self, PerlIO_list_t *layers,
                        mode = PerlIOStdio_mode(mode, tmode);
                    f = PerlIO_push(aTHX_ f, self, mode, PerlIOArg);
                    if (f) {
-                       s = PerlIOSelf(f, PerlIOStdio);
-                       s->stdio = stdio;
-                       PerlIOUnix_refcnt_inc(fileno(s->stdio));
+                       PerlIOSelf(f, PerlIOStdio)->stdio = stdio;
+                       PerlIOUnix_refcnt_inc(fileno(stdio));
+                   } else {
+                       PerlSIO_fclose(stdio);
                    }
                    return f;
                }
@@ -2912,9 +2919,8 @@ PerlIOStdio_open(pTHX_ PerlIO_funcs *self, PerlIO_list_t *layers,
                    f = PerlIO_allocate(aTHX);
                }
                if ((f = PerlIO_push(aTHX_ f, self, mode, PerlIOArg))) {
-                   PerlIOStdio * const s = PerlIOSelf(f, PerlIOStdio);
-                   s->stdio = stdio;
-                   PerlIOUnix_refcnt_inc(fileno(s->stdio));
+                   PerlIOSelf(f, PerlIOStdio)->stdio = stdio;
+                   PerlIOUnix_refcnt_inc(fileno(stdio));
                }
                return f;
            }
@@ -3709,6 +3715,8 @@ PerlIOBuf_fill(pTHX_ PerlIO *f)
     if (!b->buf)
        PerlIO_get_base(f);     /* allocate via vtable */
 
+    assert(b->buf); /* The b->buf does get allocated via the vtable system. */
+
     b->ptr = b->end = b->buf;
 
     if (!PerlIOValid(n)) {