Bug 794749

Summary: mksh is using a 32-bit register for signed integers
Product: Red Hat Enterprise Linux 6 Reporter: Jamie Duncan <jduncan>
Component: mkshAssignee: Michal Hlavinka <mhlavink>
Status: CLOSED NOTABUG QA Contact: qe-baseos-tools-bugs
Severity: medium Docs Contact:
Priority: medium    
Version: 6.2CC: jduncan, mfranc
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2012-03-01 09:15:10 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:

Description Jamie Duncan 2012-02-17 14:23:00 UTC
Description of problem:

It Looks like mksh is using a 32-bit register for signed integers, so anything above 2^31 -1 rolls over to a negative value. (Note: 536870912 = 2^29)

[root@htest06 ~]# uname -r
2.6.32-220.el6.x86_64

[root@htest06 ~]# rpm -qa mksh
mksh-39-7.el6.x86_64

[root@htest06 ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 6.2 (Santiago)

[root@htest06 ~]# alternatives --config ksh

There is 1 program that provides 'ksh'.

  Selection    Command
-----------------------------------------------
*+ 1           /bin/mksh

Enter to keep the current selection[+], or type selection number:


Version-Release number of selected component (if applicable):
RHEL 6.2

How reproducible:
Easy to reproduce

Steps to Reproduce:

$ echo "2^29 = $(( 1 * 536870912 ))"
2^29 = 536870912
$ echo "2^30 = $(( 2 * 536870912 ))"
2^30 = 1073741824
$ echo "2^31 = $(( 4 * 536870912 ))"
2^31 = -2147483648
$ echo "2^31 - 1 = $(( 4 * 536870912 - 1 ))"
2^31 - 1 = 2147483647
  
Actual results:

-2147483648

Expected results:

2147483648

Additional info:

Comment 1 Michal Hlavinka 2012-02-29 09:31:17 UTC
reproducible with mksh(rhel6), not reproducible with pdksh(rhel5)

Comment 2 Michal Hlavinka 2012-03-01 09:15:10 UTC
I talked with upstream and this is expected and documented behaviour:

$ man mksh

"""
Arithmetic expressions
...
 Expressions are calculated using signed arithmetic and the mksh_ari_t type (a 32-bit signed integer), unless they begin with a sole ‘#’ character, in which case they use mksh_uari_t (a 32-bit unsigned integer).
"""