Bug 678157 - uninitialized variable warnings from Perl
Summary: uninitialized variable warnings from Perl
Alias: None
Product: Dogtag Certificate System
Classification: Retired
Component: Installer (pkicreate/pkiremove)
Version: 9.0
Hardware: Unspecified
OS: Unspecified
Target Milestone: ---
Assignee: Matthew Harmsen
QA Contact: Ben Levenson
Depends On:
Blocks: dogtagIPAv2 679173
TreeView+ depends on / blocked
Reported: 2011-02-16 22:30 UTC by John Dennis
Modified: 2015-01-05 00:24 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
: 679173 (view as bug list)
Last Closed:

Attachments (Terms of Use)
use not operator to test for uninitialized or non empty value (7.15 KB, patch)
2011-02-16 22:30 UTC, John Dennis
no flags Details | Diff
use not operator to test for uninitialized or non empty value (7.16 KB, patch)
2011-02-21 22:17 UTC, Matthew Harmsen
awnuk: review+
Details | Diff

Description John Dennis 2011-02-16 22:30:36 UTC
Created attachment 479227 [details]
use not operator to test for uninitialized or non empty value

pkicreate, pkiremove and pkicommon.pm can sometimes emit a warning from Perl concerning an uninitialized variable. Previous patches (e.g. from the tomcat6 porting work) changed variable initialization from the empty string (e.g. "") to the special undef value (i.e. undefined) to catch errors and make the code more robust. We really want to know the difference between a variable which has never been assigned a value vs. a variable currently set to a string which happens to be empty.

A number of places in the code were modified to use the defined() function to ascertain if a value had been assigned to the variable. Formerly many of the tests were of the form 

if $var eq ""

But if $var was uninitialized this will produce a warning because you're comparing an uninitialized variable with a string constant. We do want the warning because using an uninitialized variable probably indicates a coding or logic error.

In some cases we simply want to test if a variable has a non-empty value, i.e. its not undef and it's not the empty string. The simple and clean way to test this condition is with the ! (i.e. not) operator, e.g.:

if !$var

This evaluates to True if the variable is either uninitialized or if it's the empty string without emitting a warning about accessing an uninitialized variable. In many cases this is the logic we want.

Attached is a patch which cleans up testing against the empty string and eliminates Perl warnings about such behaviour.

Comment 1 Matthew Harmsen 2011-02-21 22:17:42 UTC
Created attachment 480008 [details]
use not operator to test for uninitialized or non empty value

Applied patch #479227 against current source

Comment 2 Matthew Harmsen 2011-02-21 22:58:54 UTC

# cd pki

# svn status | grep -v ^$ | grep -v ^P | grep -v ^X | grep -v ^?
M       base/setup/pkiremove
M       base/setup/pkicommon.pm
M       base/setup/pkicreate

# svn commit
Sending        base/setup/pkicommon.pm
Sending        base/setup/pkicreate
Sending        base/setup/pkiremove
Transmitting file data ...
Committed revision 1859.

Note You need to log in before you can comment on or make changes to this bug.