Project

Profile

Help

Bug #3521

Updated by O'Neil Delpratt over 1 year ago

Logged by T Hata in https://saxonica.plan.io/boards/3/topics/7053: 


 


 Errors in unpacking binary integers with high bit set: 

 

 ~~~ 
 
 <unpack b="8000000000000000"> 
    
    <signed> 
       
       <int size="0">0</int> 
       
       <int size="1">-128</int> 
       
       <int size="2">-32768</int> 
       
       <int size="3">-8388608</int> 
       
       <int size="4">-1</int> 
       
       <int size="5">-256</int> 
       
       <int size="6">-65536</int> 
       
       <int size="7">-16777216</int> 
       
       <int size="8">-1</int> 
    
    </signed> 
    
    <unsigned> 
       
       <int size="0">0</int> 
       
       <int size="1">128</int> 
       
       <int size="2">32768</int> 
       
       <int size="3">8388608</int> 
       
       <int size="4">2147483648</int> 
       
       <int size="5">549755813888</int> 
       
       <int size="6">140737488355328</int> 
       
       <int size="7">36028797018963968</int> 
       
       <int size="8">-9223372036854775808</int> 
    
    </unsigned> 
 
 </unpack> 
 
 ~~~ 

 

 It turns out that internally an `int` constant, rather than a `long` is used during sign extension calculation, which accounts for the error at 32-bit negative. The issue at 64 bit results from the sign extension or problems of holding an unsigned `long` with the top bit set. This has been changed so that `Big` representations are used above 7 byte unpacks. 


 


 Note that one of the EXPath QT3 tests, _EXPath-binary-unpack-unsigned-integer-012_, which unpacks all 64 bits set, has an incorrect assertion of value == -1, whereas it should be 18446744073709551615  
  

Back