Bug 794749 - mksh is using a 32-bit register for signed integers
Summary: mksh is using a 32-bit register for signed integers
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: mksh
Version: 6.2
Hardware: x86_64
OS: Linux
medium
medium
Target Milestone: rc
: ---
Assignee: Michal Hlavinka
QA Contact: qe-baseos-tools-bugs
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2012-02-17 14:23 UTC by Jamie Duncan
Modified: 2018-11-28 21:10 UTC (History)
2 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2012-03-01 09:15:10 UTC
Target Upstream Version:


Attachments (Terms of Use)

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).
"""


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