Bug 8895 - Warning in systempreferences.pl: Use of uninitialized value in length...
authorMarc Veron <veron@veron.ch>
Wed, 10 Oct 2012 05:49:36 +0000 (07:49 +0200)
committerPaul Poulain <paul.poulain@biblibre.com>
Thu, 25 Oct 2012 13:09:23 +0000 (15:09 +0200)
Clicking on Local use tab in system preferences results in warning in log file:

systempreferences.pl: Use of uninitialized value in length at (...)/admin/systempreferences.pl line 456

Reason: content field "value" in table "systempreferences" can be NULL (and is tested for length).

Added test for "defined" at to places.

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Paul Poulain <paul.poulain@biblibre.com>

admin/systempreferences.pl

index 175f6a0..41130b2 100755 (executable)
@@ -420,6 +420,7 @@ sub StringSearch {
                 my $sth = $dbh->prepare("Select variable,value,explanation,type,options from systempreferences where (variable like ?) order by variable");
                 $sth->execute($syspref);
                 while ( my $data = $sth->fetchrow_hashref ) {
+                    unless (defined $data->{value}) { $data->{value} = "";}
                     $data->{shortvalue} = $data->{value};
                     $data->{shortvalue} = substr( $data->{value}, 0, 60 ) . "..." if defined( $data->{value} ) and length( $data->{value} ) > 60;
                     push( @results, $data );
@@ -452,6 +453,7 @@ sub StringSearch {
         }
 
         while ( my $data = $sth->fetchrow_hashref ) {
+            unless (defined $data->{value}) { $data->{value} = "";}
             $data->{shortvalue} = $data->{value};
             $data->{shortvalue} = substr( $data->{value}, 0, 60 ) . "..." if length( $data->{value} ) > 60;
             push( @results, $data );