Index: /trunk/server/memcached.c
===================================================================
--- /trunk/server/memcached.c (revision 604)
+++ /trunk/server/memcached.c (revision 608)
@@ -89,5 +89,4 @@
 static int add_iov(conn *c, const void *buf, int len);
 static int add_msghdr(conn *c);
-
 
 /* time handling */
@@ -1258,7 +1257,7 @@
  * returns a response string to send back to the client.
  */
-char *do_add_delta(item *it, const int incr, unsigned int delta, char *buf) {
+char *do_add_delta(item *it, const int incr, const unsigned int delta, char *buf) {
     char *ptr;
-    unsigned int value;
+    uint32_t value;
     int res;
 
@@ -1266,5 +1265,5 @@
     while ((*ptr != '\0') && (*ptr < '0' && *ptr > '9')) ptr++;    // BUG: can't be true
 
-    value = strtol(ptr, NULL, 10);
+    value = strtoul(ptr, NULL, 10);
 
     if(errno == ERANGE) {
@@ -2652,4 +2651,5 @@
     }
 
+
     /* initialize main thread libevent instance */
     main_base = event_init();
Index: /trunk/server/ChangeLog
===================================================================
--- /trunk/server/ChangeLog (revision 606)
+++ /trunk/server/ChangeLog (revision 608)
@@ -1,2 +1,7 @@
+2007-08-21 Paul Lindner <lindner@inuus.com>
+	* Incorporate incrememnt patch from Evan Miller 
+	  <emiller@imvu.com> to define increment overflow
+	  behavior.
+
 2007-08-07 Leon Brocard <acme@astray.com>
 	* Bring the memcached.1 manpage up to date
Index: /trunk/server/thread.c
===================================================================
--- /trunk/server/thread.c (revision 595)
+++ /trunk/server/thread.c (revision 608)
@@ -463,5 +463,5 @@
  * Does arithmetic on a numeric item value.
  */
-char *mt_add_delta(item *item, int incr, unsigned int delta, char *buf) {
+char *mt_add_delta(item *item, int incr, const unsigned int delta, char *buf) {
     char *ret;
 
Index: /trunk/server/t/incrdecr.t
===================================================================
--- /trunk/server/t/incrdecr.t (revision 357)
+++ /trunk/server/t/incrdecr.t (revision 608)
@@ -2,5 +2,5 @@
 
 use strict;
-use Test::More tests => 13;
+use Test::More tests => 16;
 use FindBin qw($Bin);
 use lib "$Bin/lib";
@@ -31,4 +31,13 @@
 is(scalar <$sock>, "0\r\n", "- 5 = 0");
 
+print $sock "incr num ".(2**32-2)."\r\n";
+is(scalar <$sock>, (2**32-2)."\r\n", "+ ".(2**32-2)." = ".(2**32-2));
+
+print $sock "incr num 1\r\n";
+is(scalar <$sock>, (2**32-1)."\r\n", "+ 1 = ".(2**32-1));
+
+print $sock "incr num 1\r\n";
+is(scalar <$sock>, "0\r\n", "+ 1 = 0");
+
 print $sock "decr bogus 5\r\n";
 is(scalar <$sock>, "NOT_FOUND\r\n", "can't decr bogus key");
@@ -41,4 +50,2 @@
 print $sock "incr text 1\r\n";
 is(scalar <$sock>, "1\r\n", "hi - 1 = 0");
-
-
Index: /trunk/server/doc/protocol.txt
===================================================================
--- /trunk/server/doc/protocol.txt (revision 575)
+++ /trunk/server/doc/protocol.txt (revision 608)
@@ -280,6 +280,6 @@
 
 Note that underflow in the "decr" command is caught: if a client tries
-to decrease the value below 0, the new value will be 0. Overflow in
-the "incr" command is not checked.
+to decrease the value below 0, the new value will be 0.  Overflow in the
+"incr" command will wrap around the 32 bit mark.
 
 Note also that decrementing a number such that it loses length isn't
