Bug 2131834 - call to convert_month with a substr() parameter does not recognize the result as a string
Summary: call to convert_month with a substr() parameter does not recognize the result...
Keywords:
Status: NEW
Alias: None
Product: Red Hat Enterprise Linux 8
Classification: Red Hat
Component: perl-Date-Calc
Version: 8.5
Hardware: x86_64
OS: Linux
unspecified
medium
Target Milestone: rc
: ---
Assignee: Perl Maintainers
QA Contact: RHEL CS Apps Subsystem QE
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2022-10-03 21:07 UTC by william.nardone
Modified: 2023-07-26 10:45 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed:
Type: Bug
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Issue Tracker RHELPLAN-135595 0 None None None 2022-10-03 21:16:02 UTC

Description william.nardone 2022-10-03 21:07:35 UTC
Description of problem:
We have a block of code that processes a hash with a date key in "01/Jul/2022" format.  When we try to loop through the sorted keys with a sort procedure, we get  an error indicating that the parameter passed to the convert_month routine is not a string.  See the code below for a complete description.

hits hash
"01/Jul/2022"   Title1    4
"03/Jul/2022"   Title2    7
. . .

foreach $date (sort sortdate keys %hits){
 . . .
}

sub sortdate(){
    #parse the date format  DD/MMM/YYYY - i.e. 07/Feb/2019
    # into sortable key YYYY##DD - i.e. 20190207

    { substr($a,7,4) <=> substr($b,7,4) ||
      Decode_Month(substr($a,3,3)) <=>  Decode_Month(substr($b,3,3)) ||
      substr($a,0,2) <=> substr($b,0,2)
    }
}

When we run this, we get the following error:
Date::Calc::Decode_Month(): argument is not a string at ./xxx.pl line ###.  Which points to the line with the Decode_Month(substr($a,3,3)) 

I can work around the error by forcing the result of the substr() call to be a string.  Decode_Month("".substr($a,3,3)), but the type should have been set correctly without that, since substr returns the 3 character month string: Jan, Feb, ...

I put in extra debug prints and all of the keys in the hits array are valid date strings with a valid 3 char month abbreviation.

This code was ported over from Solaris and it is working fine there.

Version-Release number of selected component (if applicable): Date::Calc (6.4)


How reproducible:
Every time

Steps to Reproduce:
1.  See above code
2.
3.

Actual results:
Error message: Date::Calc::Decode_Month(): argument is not a string at ./xxx.pl line ###.

Expected results:
process sorted list of hash elements

Additional info:

Comment 1 Jitka Plesnikova 2022-10-04 09:41:06 UTC
Thank you for the report. However, if you want Red Hat to fix it, you have to file an official support request at <https://access.redhat.com/support/>.
Bugzilla is not a support tool.

Could you please provide a small script that can be used as a reproducer?

I am not able to reproduce it with this script:
https://jplesnik.fedorapeople.org/bugzillas/bz2131834.pl

Comment 2 william.nardone 2022-10-11 14:43:32 UTC
OK, Let me review and I'll work it with the red hat folks.  You can close.


Note You need to log in before you can comment on or make changes to this bug.