|Summary:||uninitialized variable warnings from Perl|
|Product:||[Retired] Dogtag Certificate System||Reporter:||John Dennis <jdennis>|
|Component:||Installer (pkicreate/pkiremove)||Assignee:||Matthew Harmsen <mharmsen>|
|Status:||MODIFIED ---||QA Contact:||Ben Levenson <benl>|
|Fixed In Version:||Doc Type:||Bug Fix|
|Doc Text:||Story Points:||---|
|:||679173 (view as bug list)||Environment:|
|oVirt Team:||---||RHEL 7.3 requirements from Atomic Host:|
|Bug Depends On:|
|Bug Blocks:||541012, 679173|
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
TIP: # 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.