develooper Front page | perl.perl5.porters | Postings from March 2011

[perl #85508] regression in print length undef

Thread Next
Nicholas Clark
March 6, 2011 05:50
[perl #85508] regression in print length undef
Message ID:
# New Ticket Created by  Nicholas Clark 
# Please include the string:  [perl #85508]
# in the subject line of all future correspondence about this issue. 
# <URL: >

This is a bug report for perl from,
generated with the help of perlbug 1.39 running under perl 5.13.4.

[Please describe your issue here]

In fixing a related bug, d88e091f66003672 introduced a regression when printing
the length of an undefined value:

$ ./perl  -wle 'print length undef'

$ ./perl  -wle 'print length $a'
Name "main::a" used only once: possible typo at -e line 1.

$ ./perl^  -wle 'print length undef'
Use of uninitialized value in print at -e line 1.

$ ./perl^  -wle 'print length $a'
Name "main::a" used only once: possible typo at -e line 1.
Use of uninitialized value in print at -e line 1.

It's not obvious to me why this code change causes this behaviour change.
It doesn't seem to be to do with list context.

commit d88e091f660036722622a815efa9ef3779605ea6
Author: Ben Morrow <>
Date:   Fri Aug 20 18:35:58 2010 +0100

    Fix my $x = 3; $x = length(undef);.
    Assignment of length() to a lexical is optimized by passing the
    assigned-to variable as TARG, avoiding a pp_padsv and pp_sassign.
    9f621b which changed length(undef) to return undef didn't take this into
    account, and used SETs (which doesn't set TARG), so the code above left
    $x == 3.

diff --git a/pp.c b/pp.c
index 0da8bba..fcb7ff2 100644
--- a/pp.c
+++ b/pp.c
@@ -3105,8 +3105,10 @@ PP(pp_length)
            = sv_2pv_flags(sv, &len,
-       if (!p)
-           SETs(&PL_sv_undef);
+       if (!p) {
+           sv_setsv(TARG, &PL_sv_undef);
+           SETTARG;
+       }
        else if (DO_UTF8(sv)) {
            SETi(utf8_length((U8*)p, (U8*)p + len));
@@ -3119,7 +3121,8 @@ PP(pp_length)
     } else {
-       SETs(&PL_sv_undef);
+       sv_setsv_nomg(TARG, &PL_sv_undef);
+       SETTARG;

[snip tests for bug fixed]

Nicholas Clark

[Please do not change anything below this line]
Site configuration information for perl 5.13.4:

Configured by nick at Sun Mar  6 11:55:52 GMT 2011.

Summary of my perl5 (revision 5 version 13 subversion 4) configuration:
  Commit id: d88e091f660036722622a815efa9ef3779605ea6
    osname=linux, osvers=, archname=x86_64-linux-thread-multi
    uname='linux eris #4 smp tue sep 21 09:54:22 bst 2010 x86_64 gnulinux '
    config_args='-Dusethreads -Dprefix=~/Sandpit/bisect -Dcc=ccache gcc -Dld=gcc -Dnoextensions=IPC/SysV -Dusedevel -de'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=define, usemultiplicity=define
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
    cc='ccache gcc', ccflags ='-DFOO -D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    cppflags='-DFOO -D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
    ccversion='', gccversion='4.3.2', gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='gcc', ldflags =' -fstack-protector -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib /lib64 /usr/lib64
    libs=-lnsl -ldb -ldl -lm -lcrypt -lutil -lpthread -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
    libc=/lib/, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fPIC', lddlflags='-shared -O2 -L/usr/local/lib -fstack-protector'

Locally applied patches:

@INC for perl 5.13.4:

Environment for perl 5.13.4:
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PERL_BADLANG (unset)

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About