kutsurak / python-bitstring

Automatically exported from code.google.com/p/python-bitstring
0 stars 0 forks source link

BitArray concatenation sometimess modifies second argument #133

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Observe the following:

>>> from bitstring import BitArray
>>> a = BitArray(bin='0')
>>> b = BitArray(bin='11')
>>> a + b
BitArray('0b011')
>>> a + b
BitArray('0x3')
>>> a + b
BitArray('0b00011')
>>> a + b
BitArray('0b000011')
>>> a + b
BitArray('0b0000011')

Tested using Python 2.7.3 and bitstring 3.1.0.

Original issue reported on code.google.com by gerardl...@gmail.com on 16 Mar 2013 at 5:23

GoogleCodeExporter commented 9 years ago
Note that this is not always the case, so it definitely seems to be a bug.

>>> from bitstring import BitArray
>>> a = BitArray(bin='0')
>>> b = BitArray(bin='1')
>>> a + b
BitArray('0b01')
>>> a + b
BitArray('0b01')
>>> a + b
BitArray('0b01')

Original comment by gerardl...@gmail.com on 16 Mar 2013 at 5:26

GoogleCodeExporter commented 9 years ago
Thanks - it doesn't appear to be a new bug in 3.1.0 so I'm rather surprised no 
one has reported it before. I'll get a fix out fairly soon.

Original comment by dr.scott...@gmail.com on 16 Mar 2013 at 5:57

GoogleCodeExporter commented 9 years ago
Fixed in r. 970. The bug was related to not using an explicit copy when 
constructing an immutable type, which returned a cached bitstring as an 
optimisation and was then modified. Problem only occurred when the second 
argument to the add was longer than the first.

Original comment by dr.scott...@gmail.com on 20 Mar 2013 at 3:37