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

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

Thread Next
From:
lallip @ cs . rpi . edu
Date:
November 23, 2005 00:34
Subject:
[perl #37731] junk and uninit'ed values in tied scalars
Message ID:
rt-3.0.11-37731-124752.9.1873453925335@perl.org
# New Ticket Created by  lallip@cs.rpi.edu 
# Please include the string:  [perl #37731]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/rt3/Ticket/Display.html?id=37731 >


This is a bug report for perl from lallip@cs.rpi.edu,
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
behavior. 


[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
    category=core
    severity=medium
---
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:
  Platform:
    osname=solaris, osvers=2.10, archname=sun4-solaris
    uname='sunos slurm.cs.rpi.edu 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 cf_email=labstaff@cs.rpi.edu -A perladmin=labstaff@cs.rpi.edu -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
  Compiler:
    cc='cc', ccflags =' -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O',
    cppflags=''
    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/libc.so, so=so, useshrplib=true, libperl=libperl.so
    gnulibc_version=''
  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:
    /usr/local/lib/perl5/site_perl/5.8.5/sun4-solaris/auto/
    /usr/local/lib/perl5/site_perl/5.8.5/sun4-solaris/
    /usr/local/lib/perl5/site_perl/5.8.5/sun4-solaris/Bundle/
    /cs/lallip/lib/sun4-solaris
    /cs/lallip/lib
    /cs/lallip/lib/perl5/site_perl/5.8.5//sun4-solaris
    /cs/lallip/lib/perl5/site_perl/5.8.5/
    /cs/lallip/lib/perl5/site_perl/5.8.0/sun4-solaris
    /cs/lallip/lib/perl5/site_perl/5.8.0
    /cs/lallip/lib/sun4-solaris
    /software/perl-5.8.5-0/pkg/lib/5.8.5/sun4-solaris
    /software/perl-5.8.5-0/pkg/lib/5.8.5
    /usr/local/lib/perl5/site_perl/5.8.5/sun4-solaris
    /usr/local/lib/perl5/site_perl/5.8.5
    /usr/local/lib/perl5/site_perl
    /software/perl-5.8.5-0/pkg/lib/vendor_perl/5.8.5/sun4-solaris
    /software/perl-5.8.5-0/pkg/lib/vendor_perl/5.8.5
    /software/perl-5.8.5-0/pkg/lib/vendor_perl
    .

---
Environment for perl v5.8.5:
    HOME=/cs/lallip
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH=/usr/local/lib/5.8.0/sun4-solaris/CORE/
    LOGDIR (unset)
    PATH=/usr/local/bin:/usr/local/sbin:/usr/openwin/bin:/usr/dt/bin:/usr/bin:/usr/sbin:/bin:/sbin:/usr/ucb:/usr/ccs/bin
    PERL5LIB=/usr/local/lib/perl5/site_perl/5.8.5/sun4-solaris/auto/:/usr/local/lib/perl5/site_perl/5.8.5/sun4-solaris/:/usr/local/lib/perl5/site_perl/5.8.5/sun4-solaris/Bundle/:/cs/lallip/lib:/cs/lallip/lib/perl5/site_perl/5.8.5/:/cs/lallip/lib/perl5/site_perl/5.8.0:/cs/lallip/lib/sun4-solaris
    PERL_BADLANG (unset)
    SHELL=/usr/local/bin/bash


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About