Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

diagnostics.pm suppresses 'Use of uninitialized value in range (or flip)' warning #10017

Closed
p5pRT opened this issue Dec 11, 2009 · 6 comments
Closed

Comments

@p5pRT
Copy link

p5pRT commented Dec 11, 2009

Migrated from rt.perl.org#71204 (status was 'resolved')

Searchable as RT71204$

@p5pRT
Copy link
Author

p5pRT commented Dec 11, 2009

From Gene.Sullivan@mediatek.com

Bug Summary

diagnostics.pm suppresses the following type of warning
when warnings.pm is in effect​:
  Use of uninitialized value in range (or flip)

Evidence

Here, we get the warning message, as expected​:
  $ perl -w -e 'my $x = 1..3'
  Use of uninitialized value in range (or flip) at -e line 1.
  $

Now, add diagnostics to get a more verbose explanation
of the warning message​:
  $ perl -w -e 'my $x = 1..3' -Mdiagnostics
  $

There are two problems​:
1. diagnostics does not display any additional information.
2. diagnostics suppresses the message generated by warnings.pm.

A third problem occurs if diagnostics is used in conjunction with
  use warnings FATAL => 'all';
We expect a script to die because of the warning. But, the
script will not die if diagnostics is used.

The problem occurs under both methods of using diagnostics​:
1. From the command line​:
  perl -Mdiagnostics
2. Inside source code​:
  use diagnostics;

When diagnostics.pm is used with warnings.pm, we expect to get more
information about the warning. We expect to get the same information
displayed by the splain utility​:

$ echo 'Use of uninitialized value in range (or flip)' | splain
Use of uninitialized value in range (or flip) (#1)
  (W uninitialized) An undefined value was used as if it were already
  defined. It was interpreted as a "" or a 0, but maybe it was a mistake..
  To suppress this warning assign a defined value to your variables.

  To help you figure out what was undefined, perl tells you what operation
  you used the undefined value in. Note, however, that perl optimizes your
  program and the operation displayed in the warning may not necessarily
  appear literally in your program. For example, "that $foo" is
  usually optimized into "that " . $foo, and the warning will refer to
  the concatenation (.) operator, even though there is no . in your
  program.

Patch

The problem is fixed by adding the following line to diagnostics.pm​:
  local $.;

This is the patch (diff -u)​:

Inline Patch
--- diagnostics.pm      2009-06-15 04:21:42.000000000 -0400
+++ diagnostics.pm.fix  2009-12-05 10:29:53.096561000 -0500
@@ -222,6 +222,7 @@

 local $| = 1;
 my $_;
+local $.;

 my $standalone;
 my(%HTML_2_Troff, %HTML_2_Latin_1, %HTML_2_ASCII_7);


Although, splain is not affected by this issue, for completeness\, here is the same patch for splain​:
Inline Patch
--- splain      2009-06-15 04:21:43.000000000 -0400
+++ splain.fix  2009-12-09 11:06:43.570183000 -0500
@@ -224,6 +224,7 @@

 local $| = 1;
 my $_;
+local $.;

 my $standalone;
 my(%HTML_2_Troff, %HTML_2_Latin_1, %HTML_2_ASCII_7);


Test ====

This test should fail on the current diagnostics.pm,
but should pass on the fixed version.

use warnings;
use strict;
use Test​::More tests => 1;

use diagnostics;
close STDERR;
open STDERR, '>', \my $buf or die $!;
my $x = 1..3;
like($buf, qr/Use of uninitialized value in range/, 'range warning');

Version

The $VERSION of diagnostics.pm I have installed is 1.17.
The latest version I can find on CPAN is 1.18, and the issue
exists there too.

Root Cause

Here is my hypothesis on why this happens.

This is a quote from perlop#Range-Operator​:
  If either operand of scalar ".." is a constant expression, that operand
  is considered true if it is equal ("==") to the current input line
  number (the $. variable).

By default, $. is undefined​:
  $ perl -w -e 'print ">>>$.<<<\n"'
  Use of uninitialized value in concatenation (.) or string at -e line 1.
  >>><<<
  $

But, when you use [doc​://diagnostics], $. becomes defined​:
  $ perl -w -e 'print ">>>$.<<<\n"' -Mdiagnostics
  >>>0<<<
  $

So, it seems that diagnostics has the side effect
of initializing the $. variable. I see some calls
to open in the diagnostics.pm source code.
Perhaps diagnostics is opening a file handle which
is giving the global $. variable a value, thereby
suppressing the warning message.

Perl Info

Flags:
    category=library
    severity=low

Site configuration information for perl 5.10.0:

Configured by root at Mon Jun 15 16:10:47 CST 2009.

Summary of my perl5 (revision 5 version 10 subversion 0) configuration:
  Platform:
    osname=linux, osvers=2.6.9-67.elsmp, archname=x86_64-linux
    uname='linux 2.6.9-67.elsmp #1 smp wed nov 7 13:56:44 est 2007 x86_64 x86_64 x86_64 gnulinux '
    config_args='-de -Dprefix=/oss/perl/5.10.0/x86_64'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=undef, usemultiplicity=undef
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-fno-strict-aliasing -pipe -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm',
    optimize='-O2',
    cppflags='-fno-strict-aliasing -pipe -I/usr/include/gdbm'
    ccversion='', gccversion='3.4.6 20060404 (Red Hat 3.4.6-9)', 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='cc', ldflags =''
    libpth=/lib /usr/lib /lib64 /usr/lib64
    libs=-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
    libc=/lib/libc-2.3.4.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.3.4'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fPIC', lddlflags='-shared -O2'

Locally applied patches:



@INC for perl 5.10.0:
    /oss/perl/5.10.0/x86_64/lib/5.10.0/x86_64-linux
    /oss/perl/5.10.0/x86_64/lib/5.10.0
    /oss/perl/5.10.0/x86_64/lib/site_perl/5.10.0/x86_64-linux
    /oss/perl/5.10.0/x86_64/lib/site_perl/5.10.0
    .


Environment for perl 5.10.0:
    HOME=/home/gsulliva
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH=/oss/perl/5.10.0/x86_64/lib64:/oss/tcl/8.4.19/x86_64/lib:/oss/tcl/8.4.19/x86_64/lib/tcl8.4:/oss/tcl/8.4.19/x86_64/lib/tclx8.4:/lib64:/lib:
    LOGDIR (unset)
    PATH=/oss/perl/5.10.0/x86_64/bin:/usr/kerberos/bin:/usr/bin:/bin:/usr/X11R6/bin:/usr/sbin:/sbin
    PERLDOC=-i
    PERL_BADLANG (unset)
    SHELL=/bin/tcsh




@p5pRT
Copy link
Author

p5pRT commented Dec 12, 2009

From @ikegami

On Fri, Dec 11, 2009 at 12​:44 PM, Gene Sullivan
<perlbug-followup@​perl.org>wrote​:

# New Ticket Created by Gene Sullivan
# Please include the string​: [perl #71204]
# in the subject line of all future correspondence about this issue.
# <URL​: http​://rt.perl.org/rt3/Ticket/Display.html?id=71204 >

diagnostics.pm suppresses the following type of warning
when warnings.pm is in effect​:
Use of uninitialized value in range (or flip)

Attached is the patch in git format.

splain needs not be patched since it's generated from diagnostics.pm.

I wanted to add a regression test, but I couldn't find where
diagostics.pmwas being tested.

- Eric

@p5pRT
Copy link
Author

p5pRT commented Dec 12, 2009

From @ikegami

0001-diagnostics-hides-warnings-RT-71204.patch
From e2c32c98e851a2bb7f0d7b689eecb870befe22ed Mon Sep 17 00:00:00 2001
From: Gene Sullivan
Date: Sat, 12 Dec 2009 11:24:43 -0800
Subject: [PATCH] diagnostics hides warnings RT#71204

---
 lib/diagnostics.pm |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/lib/diagnostics.pm b/lib/diagnostics.pm
index d65df19..d754fd5 100644
--- a/lib/diagnostics.pm
+++ b/lib/diagnostics.pm
@@ -222,6 +222,7 @@ my $WHOAMI = ref bless [];  # nobody's business, prolly not even mine
 
 local $| = 1;
 my $_;
+local $.;
 
 my $standalone;
 my(%HTML_2_Troff, %HTML_2_Latin_1, %HTML_2_ASCII_7);
-- 
1.6.5.2

@p5pRT
Copy link
Author

p5pRT commented Dec 12, 2009

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Dec 14, 2009

From @rgarcia

2009/12/11 Gene Sullivan <perlbug-followup@​perl.org>​:

Patch

The problem is fixed by adding the following line to diagnostics.pm​:
   local $.;

This is the patch (diff -u)​:

Thanks for the patch. It's now applied to bleadperl as change
412147f.

@p5pRT
Copy link
Author

p5pRT commented Dec 14, 2009

@rgs - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant