Changeset 608

Show
Ignore:
Timestamp:
08/22/07 04:03:01 (1 year ago)
Author:
plindner
Message:

Incorporate incrememnt patch from Evan Miller
<emiller@imvu.com> to define increment overflow behavior.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/server/ChangeLog

    r606 r608  
     12007-08-21 Paul Lindner <lindner@inuus.com> 
     2        * Incorporate incrememnt patch from Evan Miller  
     3          <emiller@imvu.com> to define increment overflow 
     4          behavior. 
     5 
    162007-08-07 Leon Brocard <acme@astray.com> 
    27        * Bring the memcached.1 manpage up to date 
  • trunk/server/doc/protocol.txt

    r575 r608  
    280280 
    281281Note that underflow in the "decr" command is caught: if a client tries 
    282 to decrease the value below 0, the new value will be 0. Overflow in 
    283 the "incr" command is not checked
     282to decrease the value below 0, the new value will be 0. Overflow in the 
     283"incr" command will wrap around the 32 bit mark
    284284 
    285285Note also that decrementing a number such that it loses length isn't 
  • trunk/server/memcached.c

    r604 r608  
    8989static int add_iov(conn *c, const void *buf, int len); 
    9090static int add_msghdr(conn *c); 
    91  
    9291 
    9392/* time handling */ 
     
    12581257 * returns a response string to send back to the client. 
    12591258 */ 
    1260 char *do_add_delta(item *it, const int incr, unsigned int delta, char *buf) { 
     1259char *do_add_delta(item *it, const int incr, const unsigned int delta, char *buf) { 
    12611260    char *ptr; 
    1262     unsigned int value; 
     1261    uint32_t value; 
    12631262    int res; 
    12641263 
     
    12661265    while ((*ptr != '\0') && (*ptr < '0' && *ptr > '9')) ptr++;    // BUG: can't be true 
    12671266 
    1268     value = strtol(ptr, NULL, 10); 
     1267    value = strtoul(ptr, NULL, 10); 
    12691268 
    12701269    if(errno == ERANGE) { 
     
    26522651    } 
    26532652 
     2653 
    26542654    /* initialize main thread libevent instance */ 
    26552655    main_base = event_init(); 
  • trunk/server/t/incrdecr.t

    r357 r608  
    22 
    33use strict; 
    4 use Test::More tests => 13
     4use Test::More tests => 16
    55use FindBin qw($Bin); 
    66use lib "$Bin/lib"; 
     
    3131is(scalar <$sock>, "0\r\n", "- 5 = 0"); 
    3232 
     33print $sock "incr num ".(2**32-2)."\r\n"; 
     34is(scalar <$sock>, (2**32-2)."\r\n", "+ ".(2**32-2)." = ".(2**32-2)); 
     35 
     36print $sock "incr num 1\r\n"; 
     37is(scalar <$sock>, (2**32-1)."\r\n", "+ 1 = ".(2**32-1)); 
     38 
     39print $sock "incr num 1\r\n"; 
     40is(scalar <$sock>, "0\r\n", "+ 1 = 0"); 
     41 
    3342print $sock "decr bogus 5\r\n"; 
    3443is(scalar <$sock>, "NOT_FOUND\r\n", "can't decr bogus key"); 
     
    4150print $sock "incr text 1\r\n"; 
    4251is(scalar <$sock>, "1\r\n", "hi - 1 = 0"); 
    43  
    44  
  • trunk/server/thread.c

    r595 r608  
    463463 * Does arithmetic on a numeric item value. 
    464464 */ 
    465 char *mt_add_delta(item *item, int incr, unsigned int delta, char *buf) { 
     465char *mt_add_delta(item *item, int incr, const unsigned int delta, char *buf) { 
    466466    char *ret; 
    467467