develooper Front page | perl.perl5.porters | Postings from January 2001

[ID 20010128.002] 2 bugs in (undef - integer) in IV arithmetic

Thread Next
From:
nick
Date:
January 28, 2001 10:31
Subject:
[ID 20010128.002] 2 bugs in (undef - integer) in IV arithmetic
Message ID:
E14Mwax-0001zV-00@Bagpuss.unfortu.net

This is a bug report for perl from nick@talking.bollo.cx,
generated with the help of perlbug 1.33 running under perl v5.7.0.


-----------------------------------------------------------------
[Please enter your report here]

$ perl -wle '$a += 0x80000001; print $a'                   
2147483649
$ perl -wle '$a += 0x80000000; print $a'
2147483648
$ perl -wle '$a += 0x7FFFFFFF; print $a'
2147483647
$ perl -wle '$a -= 0x7FFFFFFF; print $a'
2147483649
$ perl -wle '$a -= 0x80000000; print $a'
-2147483648
$ perl -wle '$a -= 0x80000001; print $a'
Use of uninitialized value in subtraction (-) at -e line 1.
-0

D'oh squared. 2 bugs
and
D'oh squared. No tests spotted this

--- pp.c.orig	Sat Jan 27 04:21:24 2001
+++ pp.c	Sun Jan 28 18:16:25 2001
@@ -1266,11 +1268,17 @@
 		if (value <= (UV)IV_MIN) {
 		    /* 2s complement assumption.  */
 		    SETi(-(IV)value);
-		    RETURN;
-		} /* else drop through into NVs below */
+		} else {
+		    SETn(-(NV)value);
+		}
+		RETURN;
 	    } else {
 		dPOPiv;
-		SETu((UV)-value);
+		/* 2s complement assumption.  */
+		if (value == IV_MIN)
+		    SETu((UV)IV_MIN);
+		else
+		    SETi(-value);
 		RETURN;
 	    }
 	} else {

$ ./perl -wle '$a += 0x80000001; print $a'
2147483649
$ ./perl -wle '$a += 0x80000000; print $a'
2147483648
$ ./perl -wle '$a += 0x7FFFFFFF; print $a'
2147483647
$ ./perl -wle '$a -= 0x7FFFFFFF; print $a'
-2147483647
$ ./perl -wle '$a -= 0x80000000; print $a'
-2147483648
$ ./perl -wle '$a -= 0x80000001; print $a'
-2147483649


Should regression tests to make sure that the answer is correct go in
op/arith.t ?
Where should regression tests to make sure that no spurious warnings are
issued go ?

Nicholas Clark

[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
    category=core
    severity=high
---
Site configuration information for perl v5.7.0:

Configured by nick at Thu Jan 18 19:24:14 GMT 2001.

Summary of my perl5 (revision 5.0 version 7 subversion 0) configuration:
  Platform:
    osname=linux, osvers=2.2.17-rmk1, archname=armv4l-linux
    uname='linux bagpuss.unfortu.net 2.2.17-rmk1 #9 fri dec 8 23:52:12 gmt 2000 armv4l unknown '
    config_args='-Dusedevel -Ubincompat5005 -Uinstallusrbinperl -Dcf_email=nick@talking.bollo.cx -Dperladmin=nick@talking.bollo.cx -Dinc_version_list=  -Dinc_version_list_init=0 -Duseperlio -des'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
  Compiler:
    cc='cc', ccflags ='-fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2',
    cppflags='-fno-strict-aliasing -I/usr/local/include'
    ccversion='', gccversion='2.95.2 20000220 (Debian GNU/Linux)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=8
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=4, usemymalloc=n, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -lndbm -ldb -ldl -lm -lc -lposix -lcrypt -lutil
    perllibs=-lnsl -ldl -lm -lc -lposix -lcrypt -lutil
    libc=/lib/libc-2.1.3.so, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:
    DEVEL8452

---
@INC for perl v5.7.0:
    /usr/local/lib/perl5/5.7.0/armv4l-linux
    /usr/local/lib/perl5/5.7.0
    /usr/local/lib/perl5/site_perl/5.7.0/armv4l-linux
    /usr/local/lib/perl5/site_perl/5.7.0
    /usr/local/lib/perl5/site_perl
    .

---
Environment for perl v5.7.0:
    HOME=/home/nick
    LANG (unset)
    LANGUAGE (unset)
    LC_CTYPE=en_GB.ISO-8859-1
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/nick/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games:/sbin:/usr/sbin:/usr/local/sbin
    PERL_BADLANG (unset)
    SHELL=/bin/bash


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About