free: called with unallocated block argument

2009-02-21 Thread phil
Configuration Information [Automatically generated, do not change]:
Machine: i686
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i686' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i686-pc-linux-gnu' 
-DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL 
-DHAVE_CONFIG_H   -I.  -I. -I./include -I./lib   -g -O2
uname output: Linux Arcturus 2.6.27.15jpmr #20 SMP Sun Feb 8 12:51:35 CET 2009 
i686 GNU/Linux
Machine Type: i686-pc-linux-gnu

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

Description:
Problem with auto completion :
ls[space][TAB]
gives the follwing abort :
malloc: /Users/chet/src/bash/src/parse.y:5561: assertion botched
free: called with unallocated block argument
last command: ls
Aborting...Abandon

If /etc/bash_completion is suppressed, problem disapears.
My bash_completion is : 
$Id: bash_completion,v 1.872 2006/03/01 16:20:18 ianmacd Exp $

Repeat-By:
ls[space] [TAB]
or 
cd[space][TAB]
and several other commands.






bash crash processing b=b+1 after array read

2013-02-24 Thread phil colbourn
phil@rex:~$ unset a b X; declare -i a b=1; declare -ia X=(1 2 3);
phil@rex:~$ unset a b X; declare -i a b=1; declare -ia X=(1 2 3); (( a=X[b]
)); echo $a
2
phil@rex:~$ cd Development/pc-z80
phil@rex:~/Development/pc-z80$ chmod +x pc-crash-bash.bash
phil@rex:~/Development/pc-z80$ ./pc-crash-bash.bash
Howto crash bash2
phil@rex:~/Development/pc-z80$ ./pc-crash-bash.bash
Howto crash bash
2
phil@rex:~/Development/pc-z80$ ./pc-crash-bash.bash
Howto crash bash
2
phil@rex:~/Development/pc-z80$ ./pc-crash-bash.bash
Howto crash bash
3
phil@rex:~/Development/pc-z80$ ./pc-crash-bash.bash
Howto crash bash
200
phil@rex:~/Development/pc-z80$ ./pc-crash-bash.bash
Howto crash bash
Segmentation fault (core dumped)
phil@rex:~/Development/pc-z80$ ./pc-crash-bash.bash
Howto crash bash
Segmentation fault (core dumped)
phil@rex:~/Development/pc-z80$ ./pc-crash-bash.bash
Howto crash bash
Segmentation fault (core dumped)
phil@rex:~/Development/pc-z80$ ./pc-crash-bash.bash
Howto crash bash
100
phil@rex:~/Development/pc-z80$ ./pc-crash-bash.bash
Howto crash bash
This works: 100Segmentation fault (core dumped)
phil@rex:~/Development/pc-z80$ ./pc-crash-bash.bash
Howto crash bash
This works: 100
Segmentation fault (core dumped)
phil@rex:~/Development/pc-z80$ ./pc-crash-bash.bash
Howto crash bash
This works: 100
Segmentation fault (core dumped)
phil@rex:~/Development/pc-z80$ ./pc-crash-bash.bash
Howto crash bash
This works: 100
This works: 200
Segmentation fault (core dumped)
phil@rex:~/Development/pc-z80$ ./pc-crash-bash.bash
Howto crash bash
This works: 100
This works: 200
But a 'b=b+1' after an array read crashes bash.
Segmentation fault (core dumped)
phil@rex:~/Development/pc-z80$ ./pc-crash-bash.bash
Howto crash bash
This works: 100
This works: 200
This works: 200
But a 'b=b+1' after an array read crashes bash.
Segmentation fault (core dumped)
phil@rex:~/Development/pc-z80$ ./pc-crash-bash.bash
Howto crash bash
This works: 100
This works: 200
This works: 200
But a 'b=b+1' after an array read crashes bash.
Segmentation fault (core dumped)
phil@rex:~/Development/pc-z80$ declare -ia X=({0..1000}); echo ${X[3]}
3
phil@rex:~/Development/pc-z80$ declare -ia X=({0..1000..100}); echo ${X[3]}
300
phil@rex:~/Development/pc-z80$ ./pc-crash-bash.bash
Howto crash bash
This works: a=-1  b=2
This works: a=-1  b=3
This works: a=300  b=3
This works: a=300  b=4
This works: a=400  b=5
This works: a=500  b=6
This works: a=500  b=8
This works: a=500  b=10
This works: a=0  b=11
This works: a=0  b=12
This works: a=0  b=13
This works: a=0  b=14
But a 'b=b+1' after an array read crashes bash.
Segmentation fault (core dumped)
phil@rex:~/Development/pc-z80$ ./pc-crash-bash.bash
Howto crash bash
This works: a=-1  b=2
This works: a=-1  b=3
This works: a=300  b=3
This works: a=300  b=4
This works: a=400  b=5
This works: a=500  b=6
This works: a=500  b=8
This works: a=500  b=10
This works: a=0  b=11
This works: a=0  b=12
This works: a=0  b=13
This works: a=0  b=14
But a 'b=b+1' after an array read crashes bash.
Segmentation fault (core dumped)
phil@rex:~/Development/pc-z80$ bashbug
Processing '/etc/jupp/editorrc'...done
Processing '/etc/jupp/editorrc'...done













Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64'
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-pc-linux-gnu'
-DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL
-DHAVE_CONFIG_H   -I.  -I../bash -I../bash/include -I../bash/lib
 -D_FORTIFY_SOURCE=2 -g -O2 -fstack-protector --param=ssp-buffer-size=4
-Wformat -Werror=format-security -Wall
uname output: Linux rex 3.7.5-030705-generic #201301280206 SMP Mon Jan 28
07:07:29 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 4.2
Patch Level: 37
Release Status: release

Description:

Within (( )), 'b=b+1' will crash bash with a segment fault if it follows an
array read such as 'a=X[b]'.

Once, a test line entered into a bash prompt crashed my terminal window as
well.

Repeat-By:
#!/bin/bash printf "Howto crash bash\n" unset a b X declare -i a=-1 b=1
declare -ia X=( {0..1000..100} ) printf "But a 'b=b+1' after an array read
crashes bash.\n" (( a=X[b], b=b+1 )); printf "This crashes: a=%d b=%d\n" $a
$b

Fix:

Don't run a command after an array read

eg.

Do this instead

#!/bin/bash printf "Howto crash bash\n" unset a b X declare -i a=-1 b=1
declare -ia X=( {0..1000..100} ) printf "But a 'b=b+1' after an array read
crashes bash.\n" (( a=X[b] )); (( b=b+1 )); printf "This crashes: a=%d
b=%d\n" $a $b

More detailed script looking at what case crashes bash:

It seems that b+=1 is ok, but b=b+1 is not.


#!/b

declare -ia does not enfore integer type on initialisation

2014-02-04 Thread phil colbourn
Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64'
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-pc-linux-gnu'
-DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL
-DHAVE_CONFIG_H   -I.  -I../bash -I../bash/include -I../bash/lib
 -D_FORTIFY_SOURCE=2 -g -O2 -fstack-protector --param=ssp-buffer-size=4
-Wformat -Werror=format-security -Wall
uname output: Linux max 3.8.0-35-generic #50-Ubuntu SMP Tue Dec 3 01:24:59
UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 4.2
Patch Level: 45
Release Status: release

Description:
declare -ia not enforced if variable is initiated using =

Repeat-By:
 unset Z; declare -ia Z=( A B C ); echo ${Z[*]}; Z=( D E F ); echo ${Z[*]}
Outputs
A B C
 0 0 0
Should output:
0 0 0
0 0 0


Phil


Readline history and bash's read -e

2007-09-01 Thread Phil Endecott

Dear Bash and Readline Experts,

I have a simple shell script that reads user commands in a loop using
"read -e".  -e enables readline, but not its history feature.  Is there
any way to get readline history with bash's read builtin?

I wouldn't want to get the user's regular bash history; rather, this
program would need its own history file in the user's home directory.
For example:

read -e --historyfile=~/.myprogname_history CMD


If there's no way to do this with the read builtin, perhaps there's an
existing standalone readline wrapper program that can do this?  I
imagine it would only need a dozen lines of code.  However, it wouldn't
be possible to retain the syntax of the read builtin w.r.t. variable names:

CMD=`read_with_history -e --historyfile=~/.myprogname_history`

If such a program doesn't yet exist, I'll write it; let me know if you
would find the code useful.  Searching has found some other wrappers
(e.g. 3 at packages.debian.org) that solve the slightly different and
more complex problem of wrapping an entire  program that doesn't use
readline so that it does use it for all input.  That's not what I need
in this case.


Thanks for any advice.

Phil.
















++ causes 2 variables to increment

2016-05-15 Thread phil colbourn
Configuration Information [Automatically generated, do not change]:
Machine: i686
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i686'
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i686-pc-linux-gnu'
-DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL
-DHAVE_CONFIG_H   -I.  -I../. -I.././include -I.././lib
 -D_FORTIFY_SOURCE=2 -g -O2 -fstack-protector-strong -Wformat
-Werror=format-security -Wall
uname output: Linux m41 4.2.0-34-generic #39-Ubuntu SMP Thu Mar 10 22:11:49
UTC 2016 i686 i686 i686 GNU/Linux
Machine Type: i686-pc-linux-gnu

Bash Version: 4.3
Patch Level: 42
Release Status: release

Description:

Odd behaviour when an undefined variable is used in arithemetic expression.

((++F[word]==M)) increments both F[word] AND M

But not always.

When M is null, M seems to be treated as 0 (as expected)
When M is assigned an integer value of an integer associative array element,
something goes wrong.

(just a guess, since as you will see, this is complex to demonstrate)

This can happen when M=1 but usually when M=2.


Repeat-By:

#!/bin/bash

p(){  # print variables
  printf "F[%s]=[%d]  M=[%d]  I=[%s]\n" "$1" $((F[$1]*1)) $((M*1)) "$I"
}

t(){  # iterate - part of a program that counts word frequency and tracks
most frequent word
  p $W
  # M should not change here
  ((++F[$W]==M))&&I=  # pre-increment F[$W]. If equal to Max then I=NULL
  p $W
  # but sometimes, it does!
  ((F[$W]>M))&&M=F[$W]&&I=$W  # if F[$W]>Max then Max=F[$W]
  p $W
}

unset F
unset X
unset M
unset W
unset I

W="word"

echo setup

# it always fails, but at different iterations!

# why does it fail ever?

# an example run

# run 3
#+ t
#+ p word
#+ printf 'F[%s]=[%d]  M=[%d]  I=[%s]\n' word 2 2 ''

# here, M=2

#F[word]=[2]  M=[2]  I=[]
#+ (( ++F[word]==M ))
#+ I=
#+ p word
#+ printf 'F[%s]=[%d]  M=[%d]  I=[%s]\n' word 3 3 ''

# without changing M, it is now 3!!

#F[word]=[3]  M=[3]  I=[]
#+ (( F[word]>M ))
#+ p word
#+ printf 'F[%s]=[%d]  M=[%d]  I=[%s]\n' word 3 3 ''
#F[word]=[3]  M=[3]  I=[]
#+ set +x

# only when setting M from F[$W] or F[word] causes it to fail at iteration 2

declare -iA F;F[word]=1; M=F[word]   # fails run 2
#declare -iA F;F[$W]=1;   M=F[$W] # fails run 2

# all other ways to initialise M fail at iteration 3

#declare -iA F; declare -iA X; F[$W]=1;   X[dog]=1; M=X[dog]  # fails run 3
#declare -iA F; declare -iA X; F[$W]=1;   X[$W]=1;  M=X[$W]   # fails run 3
#declare -iA F;F[$W]=1;   M=1 # fails run 3
#declare -iA F;F[$W]=1;   M="1"   # fails run 3
#declare -iA F;F[$W]=1;   M=$((1*1))  # fails run 3
#declare -iA F;F[$W]=1;   ((M=1)) # fails run 3
#declare -iA F;F[$W]=1;   M=${F[$W]}  # fails run 3

I=$W

p $W

echo run 2
t

echo run 3
set -x
t
set +x

echo run 4
t


Fix:

declare -i M

This seems to 'fix' this.


dead.bashbug
Description: Binary data


Re: ++ causes 2 variables to increment

2016-05-17 Thread phil colbourn
Thanks Grisha,

Sorry for putting you through analysing my faulty example.




Phil

On 16 May 2016 at 05:58, Grisha Levit  wrote:

>
> On Sun, May 15, 2016 at 4:42 PM, phil colbourn 
> wrote:
> > # here, M=2
>>
>>
> It's not -- the value of $M here is the string "F[word]".  Your print
> function reports the value of "$((M*1))", which is, in fact "2": inside the
> arithmetic expression "M" is expanded to "F[word]" which is expanded to "2".
>
> > # without changing M, it is now 3!!
>
> Exactly, M does not change, it is still "F[word]".  But since F[word]
> changes, the value of $((M*1)) does change to reflect the new value of
> F[word].
>
> Instead of M=F[$W], I think you want to be doing M=${F[$W]}.
>