Right now if $inc would cause two positive ints to overflow, the result is converted to a long to prevent overflow. However, if two negative ints are added the result may overflow to a negative int.
Test
c = db.c; c.drop(); c.save( { a:NumberInt( 0x7fffffff ) } ); c.update( {}, { $inc:{ a:NumberInt( 10000 ) } } ); // The sum of two positive ints is converted to a positive long on overflow. printjson( c.find().toArray() ); c.drop(); c.save( { a:NumberInt( 0xffffffff ) } ); c.update( {}, { $inc:{ a:NumberInt( -10000 ) } } ); // The sum of two negative ints overflows to a positive int. printjson( c.find().toArray() );
- related to
-
SERVER-6399 Refactor update() code
- Closed