bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bash 2.05 mishandles ${N} on 64-bit hosts when N >= 2**31


From: Paul Eggert
Subject: Bash 2.05 mishandles ${N} on 64-bit hosts when N >= 2**31
Date: Sat, 28 Apr 2001 22:15:13 -0700 (PDT)

Configuration Information [Automatically generated, do not change]:
Machine: sparc
OS: solaris2.7
Compiler: cc -xarch=v9
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='sparc' 
-DCONF_OSTYPE='solaris2.7' -DCONF_MACHTYPE='sparc-sun-solaris2.7' 
-DCONF_VENDOR='sun' -DSHELL  -DHAVE_CONFIG_H  -D_LARGEFILE_SOURCE 
-D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -I.  -I.. -I../include -I../lib 
-I/tmp/prefix/include -g
uname output: SunOS sic.twinsun.com 5.7 Generic_106541-15 sun4u sparc 
SUNW,UltraSPARC-IIi-Engine
Machine Type: sparc-sun-solaris2.7

Bash Version: 2.05
Patch Level: 0
Release Status: release

Description:
        On a host with 64-bit 'long' and 32-bit 'int', Bash mishandles
        ${N} when N >= 2**31.

Repeat-By:
        $ set a
        $ echo ${#4294967297} ${4294967297}
        1 a

        The output should be '0', not '1 a'.

Fix:

2001-04-28  Paul Eggert  <eggert@twinsun.com>

        * subst.h (get_dollar_var_value): Now takes long, not int.
        * subst.c: (get_dollar_var_value, parameter_brace_expand_length):
        Use legal_number to convert, not atoi, as atoi can lose information.

===================================================================
RCS file: subst.h,v
retrieving revision 2.5
retrieving revision 2.5.0.1
diff -pu -r2.5 -r2.5.0.1
--- subst.h     2000/10/14 21:46:02     2.5
+++ subst.h     2001/04/29 05:03:42     2.5.0.1
@@ -147,7 +147,7 @@ extern WORD_LIST *expand_word_unsplit __
 extern WORD_LIST *expand_word_leave_quoted __P((WORD_DESC *, int));
 
 /* Return the value of a positional parameter.  This handles values > 10. */
-extern char *get_dollar_var_value __P((int));
+extern char *get_dollar_var_value __P((long));
 
 /* Quote a string to protect it from word splitting. */
 extern char *quote_string __P((char *));
===================================================================
RCS file: subst.c,v
retrieving revision 2.5.0.4
retrieving revision 2.5.0.5
diff -pu -r2.5.0.4 -r2.5.0.5
--- subst.c     2001/04/13 08:30:59     2.5.0.4
+++ subst.c     2001/04/29 05:03:42     2.5.0.5
@@ -1890,7 +1890,7 @@ number_of_args ()
 /* Return the value of a positional parameter.  This handles values > 10. */
 char *
 get_dollar_var_value (ind)
-     int ind;
+     long ind;
 {
   char *temp;
   WORD_LIST *p;
@@ -3863,16 +3863,13 @@ parameter_brace_expand_word (name, var_i
      int var_is_special, quoted;
 {
   char *temp, *tt;
-  int arg_index;
+  long arg_index;
   SHELL_VAR *var;
   WORD_LIST *l;
 
   /* Handle multiple digit arguments, as in ${11}. */
-  if (isdigit (*name))
-    {
-      arg_index = atoi (name);
-      temp = get_dollar_var_value (arg_index);
-    }
+  if (legal_number (name, &arg_index))
+    temp = get_dollar_var_value (arg_index);
   else if (var_is_special)      /* ${@} */
     {
       int sindex;
@@ -4069,6 +4066,7 @@ parameter_brace_expand_length (name)
 {
   char *t, *newname;
   int number;
+  long arg_index;
   WORD_LIST *list;
 #if defined (ARRAY_VARS)
   SHELL_VAR *var;
@@ -4113,9 +4111,9 @@ parameter_brace_expand_length (name)
     {
       number = 0;
 
-      if (isdigit (name[1]))           /* ${#1} */
+      if (legal_number (name +1, &arg_index))          /* ${#1} */
        {
-         t = get_dollar_var_value (atoi (name + 1));
+         t = get_dollar_var_value (arg_index);
          number = STRLEN (t);
          FREE (t);
        }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]