localtime(HUGEVAL) reports wrong number in error message
Description
If the number you pass to localtime is too big, you get a warning (and an error) message that contains the invalid argument. But it doesn't always print the right value.
Steps to Reproduce
$ perl -we '$_ = localtime 18446744073709550592'
localtime(18446744073709551616) too large at -e line 1.
localtime(18446744073709551616) failed at -e line 1.
Expected behavior
The error message should be talking about 18446744073709550592 (the value I actually passed), not 18446744073709551616 (which is nowhere in the code).
Perl configuration
Summary of my perl5 (revision 5 version 38 subversion 0) configuration:
Platform:
osname=linux
osvers=6.2.0-10011-tuxedo
archname=x86_64-linux-thread-multi
uname='linux luum 6.2.0-10011-tuxedo #14 smp preempt_dynamic wed jun 28 18:29:09 utc 2023 x86_64 x86_64 x86_64 gnulinux '
config_args='-de -Dprefix=/home/mauke/perl5/perlbrew/perls/perl-5.38.0-DEBUGGING-thread -Dman1dir=none -Dman3dir=none -Dusethreads -DDEBUGGING -Aeval:scriptdir=/home/mauke/perl5/perlbrew/perls/perl-5.38.0-DEBUGGING-thread/bin'
hint=recommended
useposix=true
d_sigaction=define
useithreads=define
usemultiplicity=define
use64bitint=define
use64bitall=define
uselongdouble=undef
usemymalloc=n
default_inc_excludes_dot=define
Compiler:
cc='cc'
ccflags ='-D_REENTRANT -D_GNU_SOURCE -fwrapv -DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'
optimize='-O2 -g'
cppflags='-D_REENTRANT -D_GNU_SOURCE -fwrapv -DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include'
ccversion=''
gccversion='11.3.0'
gccosandvers=''
intsize=4
longsize=8
ptrsize=8
doublesize=8
byteorder=12345678
doublekind=3
d_longlong=define
longlongsize=8
d_longdbl=define
longdblsize=16
longdblkind=3
ivtype='long'
ivsize=8
nvtype='double'
nvsize=8
Off_t='off_t'
lseeksize=8
alignbytes=8
prototype=define
Linker and Libraries:
ld='cc'
ldflags =' -fstack-protector-strong -L/usr/local/lib'
libpth=/usr/local/lib /usr/lib/x86_64-linux-gnu /usr/lib /usr/lib64
libs=-lpthread -ldb -ldl -lm -lcrypt -lutil -lc
perllibs=-lpthread -ldl -lm -lcrypt -lutil -lc
libc=/lib/x86_64-linux-gnu/libc.so.6
so=so
useshrplib=false
libperl=libperl.a
gnulibc_version='2.35'
Dynamic Linking:
dlsrc=dl_dlopen.xs
dlext=so
d_dlsymun=undef
ccdlflags='-Wl,-E'
cccdlflags='-fPIC'
lddlflags='-shared -O2 -g -L/usr/local/lib -fstack-protector-strong'
Characteristics of this binary (from libperl):
Compile-time options:
DEBUGGING
HAS_LONG_DOUBLE
HAS_STRTOLD
HAS_TIMES
MULTIPLICITY
PERLIO_LAYERS
PERL_COPY_ON_WRITE
PERL_DONT_CREATE_GVSV
PERL_HASH_FUNC_SIPHASH13
PERL_HASH_USE_SBOX32
PERL_MALLOC_WRAP
PERL_OP_PARENT
PERL_PRESERVE_IVUV
PERL_TRACK_MEMPOOL
PERL_USE_SAFE_PUTENV
USE_64_BIT_ALL
USE_64_BIT_INT
USE_ITHREADS
USE_LARGE_FILES
USE_LOCALE
USE_LOCALE_COLLATE
USE_LOCALE_CTYPE
USE_LOCALE_NUMERIC
USE_LOCALE_TIME
USE_PERLIO
USE_PERL_ATOF
USE_REENTRANT_API
USE_THREAD_SAFE_LOCALE
Built under linux
Compiled at Jul 18 2023 17:52:41
%ENV:
PERLBREW_BASHRC_VERSION="0.74"
PERLBREW_HOME="/home/mauke/.perlbrew"
PERLBREW_MANPATH="/home/mauke/perl5/perlbrew/perls/perl-5.38.2/man"
PERLBREW_PATH="/home/mauke/perl5/perlbrew/bin:/home/mauke/perl5/perlbrew/perls/perl-5.38.2/bin"
PERLBREW_PERL="perl-5.38.2"
PERLBREW_ROOT="/home/mauke/perl5/perlbrew"
PERLBREW_VERSION="0.94"
PERLDOC="-oman"
PERL_UNICODE="SAL"
@INC:
/home/mauke/perl5/perlbrew/perls/perl-5.38.0-DEBUGGING-thread/lib/site_perl/5.38.0/x86_64-linux-thread-multi
/home/mauke/perl5/perlbrew/perls/perl-5.38.0-DEBUGGING-thread/lib/site_perl/5.38.0
/home/mauke/perl5/perlbrew/perls/perl-5.38.0-DEBUGGING-thread/lib/5.38.0/x86_64-linux-thread-multi
/home/mauke/perl5/perlbrew/perls/perl-5.38.0-DEBUGGING-thread/lib/5.38.0
Yeah, the argument is taken as a NV when it really should be an IV if sizeof(IV) ==8. It's not the only place where this sort of bug exists.
Yeah, the argument is taken as a NV when it really should be an IV if sizeof(IV) ==8. It's not the only place where this sort of bug exists.
So, should we simply try to fix this here (i.e., in localtime()) or should we attempt a more comprehensive fix?
On 1/13/24 06:26, Leon Timmermans wrote:
Yeah, the argument is taken as a NV when it really should be an IV if sizeof(IV) ==8
Looking at the code, it appears to me that it was intended to be general but with minimal coding effort. Why not just display the too large number using NVgf to the Configured precision?
— Reply to this email directly, view it on GitHub https://github.com/Perl/perl5/issues/21827#issuecomment-1890458867, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA2DH64LKAEDHWOJJQV7KTYOKDRRAVCNFSM6AAAAABBYV2OUSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQOJQGQ2TQOBWG4. You are receiving this because you are subscribed to this thread.Message ID: @.***>