Skip Menu |

This queue is for tickets about the X11-Protocol CPAN distribution.

Report information
The Basics
Id: 3926
Status: resolved
Priority: 0/
Queue: X11-Protocol

People
Owner: Nobody in particular
Requestors: edels [...] acsys.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.51
Fixed in: 0.52



Subject: Non-numeric return value in X11::Protocol::num causes error message in X11::Protocol::get_request
In X11::Protocol, the get_request method checks for numeric values on line 2019: sub get_request { my $self = shift; my($name) = @_; my($major, $minor); $major = $self->num('Request', $name); Show quoted text
>>>>> if (int($major) != 0) { # Core request
return ($self->{'requests'}[$major], $major); } else { # Extension request croak "Unknown request `$name'" unless exists $self->{'ext_request_num'}{$name}; ($major, $minor) = @{$self->{'ext_request_num'}{$name}}; croak "Unknown request `$name'" if int($major) == 0; return ($self->{'ext_request'}{$major}[$minor], $major, $minor); } } However, the num method returns back the NAME of the request ($name) if it is not found in the const_num or ext_const_num hashes. This causes an error such as "Argument "XCMiscGetVersion" isn't numeric in int at /usr/lib/perl5/site_perl/5.8.0/X11/Protocol.pm line 2019" to be printed. Wouldn't it be preferable to have num return '0' when it doesn't find a number to hash to (thus telling it to skip to the next conditional)? Alternatively, perhaps line 2019 should be changed to: if (($major =~ /^\d+$/o) && int($major) != 0) { # Core request So it only tries to 'int' the value if it is in fact a number.
The corresponding line in version 0.52 says: if ($major =~ /^\d+$/) { # Core request which I think fixes the message. In retrospect, the behavior of num() on failed lookups is not the most fool-proof; for most calls (though not this one), it would likely be better to have something that croaked if given an invalid string was given. Returning 0 on a failed lookup would be bad in general, since for many categories there is a symbolic value corresponding to zero (e.g. as a JoinStyle, it means "Miter"), though it would match the current behavior in many circumstances.