[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Patch: Warnings from LedgerSMB::Template::CSV



When printing sales invoices in CSV format, my error logs are filling up
with errors like the following:

Use of uninitialized value $vars in substitution (s///) at
LedgerSMB/Template/CSV.pm line 78.
Use of uninitialized value $vars in substitution (s///) at
LedgerSMB/Template/CSV.pm line 79.
Use of uninitialized value $vars in pattern match (m//) at
LedgerSMB/Template/CSV.pm line 80.

I am using ledgersmb 1.3.22, with Math::BigInt::GMP.

The errors are triggered inside the LedgerSMB::Template::CSV::preprocess()
function.

For simple scalar values, preprocess() tests and will simply return if the
supplied $rawvars argument is undefined.

But in this case, $rawvars represents a valid Math::BigInt::GMP object,
which passes the defined test. However, when de-referenced, on line 72,
the underlying value of this object is undefined, which causes the pattern
matches to generate warnings.

I propose a small patch that the de-referenced Math::BigInt::GMP is tested
for defined-ness in the same way as the $rawvars argument:


--- /CSV.original.pm	2012-06-17 11:13:17.000000000 +0100
+++ CSV.pm	2012-09-13 07:35:02.415517125 +0100
@@ -68,10 +68,11 @@
 		}
 	} elsif ( !$type or $type eq 'SCALAR' or $type eq 'Math::BigInt::GMP') {
 			# Scalars or GMP objects (which are SCALAR refs) --CT
 		if ($type eq 'SCALAR' or $type eq 'Math::BigInt::GMP') {
 			$vars = $$rawvars;
+			return unless defined $vars;
 		} else {
 			$vars = $rawvars;
 		}
 		$vars =~ s/(^ +| +$)//g;
 		$vars =~ s/"/""/g;