Bug 122659 - [patch] sh(1) long arithmetics broken on certain architectures
Summary: [patch] sh(1) long arithmetics broken on certain architectures
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 7.0-RELEASE
Hardware: Any Any
: Normal Affects Only Me
Assignee: Stefan Farfeleder
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-04-11 15:50 UTC by Jaakko Heinonen
Modified: 2010-05-16 11:11 UTC (History)
0 users

See Also:


Attachments
sh-long-arith.diff (3.68 KB, patch)
2008-04-11 15:50 UTC, Jaakko Heinonen
no flags Details | Diff
file.diff (917 bytes, patch)
2008-04-11 15:50 UTC, Jaakko Heinonen
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jaakko Heinonen 2008-04-11 15:50:00 UTC
This PR partially supersedes bin/51171.

In src/bin/sh/shell.h there's a following comment:

/*
 * Type of used arithmetics. SUSv3 requires us to have at least signed long.
 */

However in sh(1) code int type is used in several places for arithmetics
which prevents long arithmetics to work on architectures where
sizeof(int) != sizeof(long).

Fix: I have attached two patches here. The first one converts places still using
int instead of arith_t to use arith_t. It also converts hardcoded format
strings to ARITH_FORMAT_STR and removes the hardcoded limitation of 10
characters for numbers.

The second patch which must be applied on top of the first one converts
arith_t from long to intmax_t. This patch is not strictly needed to comply
with SUS but it extends 32 bit arithmetics to 64 bits for example on i386.
How-To-Repeat: $ sh -c 'uname -m; echo $((2147483647 + 1))'
amd64
-2147483648
Comment 1 Stefan Farfeleder freebsd_committer freebsd_triage 2008-04-19 16:27:40 UTC
Responsible Changed
From-To: freebsd-bugs->stefanf

I will handle this.
Comment 2 dfilter service freebsd_committer freebsd_triage 2008-04-27 21:25:52 UTC
stefanf     2008-04-27 20:25:43 UTC

  FreeBSD src repository

  Modified files:        (Branch: RELENG_6)
    bin/sh               arith.h arith.y expand.c shell.h 
  Log:
  - Fix bugs where the value of arithmetic expansion$((...)) was trucated
    to type int.
  - Change the type used for arithmetic expansion to intmax_t (ie. 64 bit on all
    currently supported FreeBSD architectures).  SUSv3 requires at least type
    long but allows for larger types.  Other shells (eg. bash, zsh, NetBSD's sh)
    do that too.
  
  PR:             122659
  Submitted by:   Jaakko Heinonen (minor modifications by me)
  
  Revision  Changes    Path
  1.9.8.2   +5 -1      src/bin/sh/arith.h
  1.19.8.2  +13 -9     src/bin/sh/arith.y
  1.47.2.4  +3 -6      src/bin/sh/expand.c
  1.17.8.1  +11 -4     src/bin/sh/shell.h
_______________________________________________
cvs-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/cvs-all
To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
Comment 3 dfilter service freebsd_committer freebsd_triage 2008-04-27 21:46:51 UTC
stefanf     2008-04-27 20:46:45 UTC

  FreeBSD src repository

  Modified files:
    bin/sh               arith.h arith.y shell.h 
  Log:
  - Fix bugs where the value of arithmetic expansion$((...)) was trucated
    to type int.
  - Change the type used for arithmetic expansion to intmax_t (ie. 64 bit on all
    currently supported FreeBSD architectures).  SUSv3 requires at least type
    long but allows for larger types.  Other shells (eg. bash, zsh, NetBSD's sh)
    do that too.
  
  PR:             122659
  Submitted by:   Jaakko Heinonen (minor modifications by me)
  
  Revision  Changes    Path
  1.12      +5 -1      src/bin/sh/arith.h
  1.22      +13 -9     src/bin/sh/arith.y
  1.18      +11 -4     src/bin/sh/shell.h
_______________________________________________
cvs-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/cvs-all
To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
Comment 4 Stefan Farfeleder freebsd_committer freebsd_triage 2008-04-28 19:23:56 UTC
State Changed
From-To: open->patched

Fixed in HEAD.
Comment 5 Volker 2008-05-10 21:04:42 UTC
Stefan,

this has been committed to HEAD and RELENG_6 but not to RELENG_7. Can
you please check?

Volker
Comment 6 Stefan Farfeleder freebsd_committer freebsd_triage 2008-05-11 10:52:00 UTC
On Sat, May 10, 2008 at 07:10:04PM +0000, Volker wrote:
> The following reply was made to PR bin/122659; it has been noted by GNATS.
> 
> From: Volker <volker@vwsoft.com>
> To: bug-followup@FreeBSD.org, stefanf@freebsd.org
> Cc: jh@saunalahti.fi
> Subject: Re: bin/122659: [patch] sh(1) long arithmetics broken on certain
>  architectures
> Date: Sat, 10 May 2008 22:04:42 +0200
> 
>  Stefan,
>  
>  this has been committed to HEAD and RELENG_6 but not to RELENG_7. Can
>  you please check?

The commit to RELENG_6 was an error and backed out.  I will merge this
change to RELENG_{6,7} these days.
Comment 7 Stefan Farfeleder freebsd_committer freebsd_triage 2010-05-16 11:10:51 UTC
State Changed
From-To: patched->closed

Already merged back into 7 and 8.