Show
Ignore:
Timestamp:
10/03/07 20:45:31 (2 years ago)
Author:
plindner
Message:

Switch to unsigned 64-bit increment/decrement counters from Evan Miller and Dusgtin Sallings.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/server/memcached.c

    r615 r619  
    12591259} 
    12601260 
    1261 static void process_arithmetic_command(conn *c, token_t *tokens, const size_t ntokens, const int incr) { 
    1262     char temp[32]; 
     1261static void process_arithmetic_command(conn *c, token_t *tokens, const size_t ntokens, const bool incr) { 
     1262    char temp[sizeof("18446744073709551615")]; 
    12631263    item *it; 
    1264     unsigned int delta; 
     1264    int64_t delta; 
    12651265    char *key; 
    12661266    size_t nkey; 
     
    12891289    } 
    12901290 
    1291     delta = strtoul(tokens[2].value, NULL, 10); 
     1291    delta = strtoll(tokens[2].value, NULL, 10); 
    12921292 
    12931293    if(errno == ERANGE) { 
     
    13161316 * returns a response string to send back to the client. 
    13171317 */ 
    1318 char *do_add_delta(item *it, const int incr, const unsigned int delta, char *buf) { 
     1318char *do_add_delta(item *it, const bool incr, const int64_t delta, char *buf) { 
    13191319    char *ptr; 
    1320     uint32_t value; 
     1320    int64_t value; 
    13211321    int res; 
    13221322 
     
    13241324    while ((*ptr != '\0') && (*ptr < '0' && *ptr > '9')) ptr++;    // BUG: can't be true 
    13251325 
    1326     value = strtoul(ptr, NULL, 10); 
     1326    value = strtoull(ptr, NULL, 10); 
    13271327 
    13281328    if(errno == ERANGE) { 
     
    13301330    } 
    13311331 
    1332     if (incr != 0) 
     1332    if (incr) 
    13331333        value += delta; 
    13341334    else { 
     
    13361336        else value -= delta; 
    13371337    } 
    1338     snprintf(buf, 32, "%u", value); 
     1338    sprintf(buf, "%llu", value); 
    13391339    res = strlen(buf); 
    13401340    if (res + 2 > it->nbytes) { /* need to realloc */