develooper Front page | perl.perl5.porters | Postings from November 2005

[perl #37731] junk and uninit'ed values in tied scalars

Thread Next
lallip @ cs . rpi . edu
November 23, 2005 00:34
[perl #37731] junk and uninit'ed values in tied scalars
Message ID:
# New Ticket Created by 
# Please include the string:  [perl #37731]
# 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.35 running under perl v5.8.5.

[Please enter your report here]
The following was posted to c.l.p.m on 2005-11-19, by Eric Roode,
who noted that he did not have access to a machine which could run
perlbug.  This message is sent on his behalf:

    In the past month, three bugs have been reported in my Readonly
module, except that they turned out not to be bugs in the module, but
(sadly) bugs in Perl 5.8.  The pure-perl version of Readonly relies
on tied variables, which appear to have various colorful and
intermittent bugs. 

    Here is a short program that illustrates bug #1:

        sub foo::TIESCALAR { bless {value => $_[1]}, $_[0] }
        sub foo::FETCH { $_[0]->{value} }
        tie my $test, 'foo', 'test';
        print "$test$test\n";

This prints "testp\cX\c@" or other similar garbage. The first
interpolation prints fine; the second is reminiscent of a
non-NUL-terminated C string.

    Oddly, with a longer string:

        sub foo::TIESCALAR { bless {value => $_[1]}, $_[0] }
        sub foo::FETCH { $_[0]->{value} }
        tie my $test, 'foo', 'I snort the nose, Lucifer!';
        print "$test$test\n";

it prints "I snort the nose, Lucifer!I snort the nose, Lucifer!" as
you'd expect.  Also, if there is a space, or any other character,
between the two variables in the interpolation:

        print "$test $test\n";

there is no buggy behavior.

    Here is a short program that illustrates bug #2:

        use warnings;
        sub foo::TIESCALAR { bless {}, shift }
        sub foo::FETCH { return 2 }
        tie my $test, 'foo';
        my $bits = 3 & ~$test;

This gives the warning
        Use of uninitialized value in 1's complement (~) at....

    Finally, the mysterious Bug #3:

        sub foo::TIESCALAR { bless {value => $_[1]}, $_[0] }
        sub foo::FETCH { $_[0]->{value} }
        tie my $VAR, 'foo', 'SEARCH';
        foreach my $var ($VAR)
           print +($var eq $VAR) ? 'yes' : 'no';

This prints "no".

    Amusingly, change the "print" line to:

           print +(lc $var eq lc $VAR) ? 'yes' : 'no';

and it prints "yes".

    I had several friends try out the code I posted above for "bug
#1".  Two people had perl 5.6.1, and that did not exhibit the buggy
behavior.  All others had various forms of 5.8.x (where x ranged from
0 to 7), on various platforms (Windows, linux, FreeBSD, MacOSX,
cygwin/2000, cygwin/XP).  All 5.8.x users exhibited the buggy

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

Configured by jon at Tue Jan 11 17:19:41 EST 2005.

Summary of my perl5 (revision 5 version 8 subversion 5) configuration:
    osname=solaris, osvers=2.10, archname=sun4-solaris
    uname='sunos 5.10 s10_63 sun4u sparc sunw,ultra-5_10 '
    config_args='-d -e -A ldflags=-L/software/perl-5.8.5-0/pkg/lib/5.8.5/sun4-solaris/CORE -R/software/perl-5.8.5-0/pkg/lib/5.8.5/sun4-solaris/CORE -A prefix=/software/perl-5.8.5-0/pkg -A prefixexp=/software/perl-5.8.5-0/pkg -A siteprefix=/usr/local -A siteprefixexp=/usr/local -A d_dosuid=define -A d_mymalloc=undef -A mallocobj= -A mallocsrc= -A usemymalloc=n -A usevendorprefix=define -A vendorprefix=/software/perl-5.8.5-0/pkg -A vendorprefixexp=/software/perl-5.8.5-0/pkg -A installusrbinperl=undef -D useshrplib=true -A -A -A installsitearch=/usr/local/lib/perl5/site_perl/5.8.5/sun4-solaris -A installsitelib=/usr/local/lib/perl5/site_perl/5.8.5 -A loclibpth=/usr/local/lib -A sitearch=/usr/local/lib/perl5/site_perl/5.8.5/sun4-solaris -A sitearchexp=/usr/local/lib/perl5/site_perl/5.8.5/sun4-solaris -A sitelib=/usr/local/lib/perl5/site_perl/5.8.5 -A sitelib_stem=/usr/local/lib/perl5/site_perl -A sitelibexp=/usr/local/li!
 b/perl5/site_perl/5.8.5 -D use64bitall=undef -D use64bitint=undef'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=y, bincompat5005=undef
    cc='cc', ccflags =' -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    ccversion='Sun C 5.6 2004/07/15', gccversion='', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=4321
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/software/perl-5.8.5-0/pkg/lib/5.8.5/sun4-solaris/CORE -R/software/perl-5.8.5-0/pkg/lib/5.8.5/sun4-solaris/CORE -L/usr/lib -L/usr/ccs/lib -L/software/sunone-9.0-0/pkg/prod/lib/v8plus -L/software/sunone-9.0-0/pkg/prod/lib -L/lib -L/usr/local/lib '
    libpth=/usr/lib /usr/ccs/lib /software/sunone-9.0-0/pkg/prod/lib/v8plus /software/sunone-9.0-0/pkg/prod/lib /lib /usr/local/lib
    libs=-lsocket -lnsl -ldl -lm -lc
    perllibs=-lsocket -lnsl -ldl -lm -lc
    libc=/lib/, so=so, useshrplib=true,
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='  -R /software/perl-5.8.5-0/pkg/lib/5.8.5/sun4-solaris/CORE'
    cccdlflags='-KPIC', lddlflags='-G -L/software/perl-5.8.5-0/pkg/lib/5.8.5/sun4-solaris/CORE -R/software/perl-5.8.5-0/pkg/lib/5.8.5/sun4-solaris/CORE -L/usr/lib -L/usr/ccs/lib -L/software/sunone-9.0-0/pkg/prod/lib/v8plus -L/software/sunone-9.0-0/pkg/prod/lib -L/lib -L/usr/local/lib'

Locally applied patches:

@INC for perl v5.8.5:

Environment for perl v5.8.5:
    LANG (unset)
    LANGUAGE (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