directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Emmanuel Lecharny <>
Subject Long comparisons
Date Wed, 23 Jan 2008 00:24:45 GMT
Hi guys,

yesturday and today, I fight against a vicious bug for hours. Thanks to 
Pierre-Arnaud and Alex, I found the reason for the failures I was 

What happened is that the Key used to extract an entry from the master 
table was compared with the stored Keys using a compare() method which 
uses long, doing some simple if ( key1 > key2 ) then ... test.

This is obviously wrong if we are working with unsigned longs, because 
Java does not treat longs as unsigned, so -1 is always > to any positive 
value (because the upper bit is 1 for negative values), but java > 
operator does not take this bit into account.

After a convo with David Jencks, we agreed that we need a four steps 
comparison :

if ( x >= 0 and y >=  0) then return x > Y
if ( x < 0 and y >= 0) then return x
if ( x >= 0 and y < 0) then return y
if ( x < 0 and y < 0) then return -x < -y

I will implement such a method asap.

PS : trunk is simply broken if the DBFILES file is removed and 
regenerated, as the plugin will inject data at the wrong place, due to 
this bug, which has been introduced in october last year.

PS2 : there is a hack which seems to work :

if  ( x - y ) > 0 the return x else return y

I don't have the fuel to check what will happen when (x - y) will 
overflow though, but I will do tomorrow (unless somebody can check for me ;)

cordialement, regards,
Emmanuel L├ęcharny

View raw message