Perl-GD
Perl-GD copied to clipboard
newFromPng() leads to "Uninitialized value $pkg at Symbol.pm line 53"
After switching from Ubuntu 20 LTS (Perl Lib GD Version 2.71) to Ubuntu 22 LTS (Perl Lib GD Version 2.712.76) every Perl -w call of GD::Image->newFromPng() leads to the following error output:
Use of uninitialized value $pkg in concatenation (.) or string at /usr/lib/x86_64-linux-gnu/perl-base/Symbol.pm line 53.
In a web server environment this is annoying, because it creates an entry in the Apache server error log every time.
I just tried with GD version 2.76 (current head of master branch here) and could not reproduce the warning. There is no use of a variable named $pkg anywhere in GD, and it may instead be a problem with the Symbol module.
Could you see if 2.76 fixes your problem?
In the following example:
use strict; use GD; my $image = GD::Image->newFromPng('empty.png'); f(); sub f { my $image = GD::Image->newFromPng('empty.png'); }
only the first call of newFromPng() produces the warning "Use of uninitialized value $pkg ...", while the second one does not.
There is the following line in Image.pm: $fh = qualify_to_ref($thing,caller(2));
When the call of newFromPng() is not from within a subroutine, then caller(2) returns null. This null then goes to qualify() in Symbol.pm and to the concatenation "$name = $pkg . "::" . $name;"
Symbol.pm must have changed its behavior somehow in version 1.09 compared to 1.08, because this warning was not shown before (while the problem was already there in older versions of Image.pm).
In my opinion the problem is "caller(2)", because it assumes that one can always go 2 frames back.
See also https://rt.cpan.org/Ticket/Display.html?id=148899 Trying a fix suggested by ppisar now
Fixed with 2.78