$inc should handle negative overflow the same as positive overflow

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Done
    • Priority: Major - P3
    • 2.5.2
    • Affects Version/s: None
    • Component/s: Write Ops
    • None
    • Fully Compatible
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      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() );
      

              Assignee:
              Unassigned
              Reporter:
              Aaron Staple (Inactive)
              Votes:
              5 Vote for this issue
              Watchers:
              8 Start watching this issue

                Created:
                Updated:
                Resolved: