Index: trunk/tugelacache/dbcached.c |
— | — | @@ -541,7 +541,7 @@ |
542 | 542 | (strncmp(command, "decr ", 5) == 0)) { |
543 | 543 | char temp[32]; |
544 | 544 | unsigned int value; |
545 | | - item *it; |
| 545 | + item *it, *newit = NULL, *putit = NULL; |
546 | 546 | unsigned int delta; |
547 | 547 | char key[251]; |
548 | 548 | int res, ret; |
— | — | @@ -585,14 +585,25 @@ |
586 | 586 | |
587 | 587 | sprintf(temp, "%u", value); |
588 | 588 | res = strlen(temp); |
589 | | - memcpy(ITEM_data(it), temp, res); |
590 | | - memset(ITEM_data(it) + res, ' ', it->nbytes - res - 2); |
| 589 | + if (res + 2 > it->nbytes) { |
| 590 | + newit = |
| 591 | + item_alloc(ITEM_key(it), it->flags, it->exptime, res + 2); |
| 592 | + memcpy(ITEM_data(newit), temp, res); |
| 593 | + memcpy(ITEM_data(newit) + res, "\r\n", 2); |
| 594 | + putit = newit; |
| 595 | + } else { |
| 596 | + memcpy(ITEM_data(it), temp, res); |
| 597 | + memset(ITEM_data(it) + res, ' ', it->nbytes - res - 2); |
| 598 | + putit = it; |
| 599 | + } |
591 | 600 | cleanup_dbt(); |
592 | 601 | dbkey.data = key; |
593 | 602 | dbkey.size = strlen(key); |
594 | | - dbdata.data = it; |
595 | | - dbdata.size = ITEM_ntotal(it); |
| 603 | + dbdata.data = putit; |
| 604 | + dbdata.size = ITEM_ntotal(putit); |
596 | 605 | dbp->put(dbp, NULL, &dbkey, &dbdata, NULL); |
| 606 | + if (newit) |
| 607 | + free(newit); |
597 | 608 | out_string(c, temp); |
598 | 609 | return; |
599 | 610 | } |