<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -210,6 +210,7 @@
           &lt;t hangText=&quot;0x0003&quot;&gt;Value too large&lt;/t&gt;
           &lt;t hangText=&quot;0x0004&quot;&gt;Invalid arguments&lt;/t&gt;
           &lt;t hangText=&quot;0x0005&quot;&gt;Item not stored&lt;/t&gt;
+          &lt;t hangText=&quot;0x0006&quot;&gt;Incr/Decr on non-numeric value.&lt;/t&gt;
           &lt;t hangText=&quot;0x0081&quot;&gt;Unknown command&lt;/t&gt;
           &lt;t hangText=&quot;0x0082&quot;&gt;Out of memory&lt;/t&gt;
         &lt;/list&gt;</diff>
      <filename>doc/protocol-binary.xml</filename>
    </modified>
    <modified>
      <diff>@@ -931,6 +931,9 @@ static void write_bin_error(conn *c, protocol_binary_response_status err, int sw
     case PROTOCOL_BINARY_RESPONSE_E2BIG:
         errstr = &quot;Too large.&quot;;
         break;
+    case PROTOCOL_BINARY_RESPONSE_DELTA_BADVAL:
+        errstr = &quot;Non-numeric server-side value for incr or decr&quot;;
+        break;
     case PROTOCOL_BINARY_RESPONSE_NOT_STORED:
         errstr = &quot;Not stored.&quot;;
         break;
@@ -1028,12 +1031,17 @@ static void complete_incr_bin(conn *c) {
                c-&gt;binary_header.request.cas == ITEM_get_cas(it))) {
         /* Weird magic in add_delta forces me to pad here */
         char tmpbuf[INCR_MAX_STORAGE_LEN];
-        add_delta(c, it, c-&gt;cmd == PROTOCOL_BINARY_CMD_INCREMENT,
-                  req-&gt;message.body.delta, tmpbuf);
-        rsp-&gt;message.body.value = swap64(strtoull(tmpbuf, NULL, 10));
-        c-&gt;cas = ITEM_get_cas(it);
-        write_bin_response(c, &amp;rsp-&gt;message.body, 0, 0,
-                           sizeof(rsp-&gt;message.body.value));
+        char *adrv = add_delta(c, it, c-&gt;cmd == PROTOCOL_BINARY_CMD_INCREMENT,
+                               req-&gt;message.body.delta, tmpbuf);
+        if (strncmp(adrv, &quot;CLIENT_ERROR&quot;, 12) == 0) {
+            write_bin_error(c, PROTOCOL_BINARY_RESPONSE_DELTA_BADVAL, 0);
+        } else {
+            rsp-&gt;message.body.value = swap64(strtoull(tmpbuf, NULL, 10));
+            c-&gt;cas = ITEM_get_cas(it);
+            write_bin_response(c, &amp;rsp-&gt;message.body, 0, 0,
+                               sizeof(rsp-&gt;message.body.value));
+        }
+
         item_remove(it);         /* release our reference */
     } else if (!it &amp;&amp; req-&gt;message.body.expiration != 0xffffffff) {
         /* Save some room for the response */</diff>
      <filename>memcached.c</filename>
    </modified>
    <modified>
      <diff>@@ -68,6 +68,7 @@ extern &quot;C&quot;
     PROTOCOL_BINARY_RESPONSE_E2BIG = 0x03,
     PROTOCOL_BINARY_RESPONSE_EINVAL = 0x04,
     PROTOCOL_BINARY_RESPONSE_NOT_STORED = 0x05,
+    PROTOCOL_BINARY_RESPONSE_DELTA_BADVAL = 0x06,
     PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND = 0x81,
     PROTOCOL_BINARY_RESPONSE_ENOMEM = 0x82
   } protocol_binary_response_status;</diff>
      <filename>protocol_binary.h</filename>
    </modified>
    <modified>
      <diff>@@ -2,7 +2,7 @@
 
 use strict;
 use warnings;
-use Test::More tests =&gt; 860;
+use Test::More tests =&gt; 880;
 use FindBin qw($Bin);
 use lib &quot;$Bin/lib&quot;;
 use MemcachedTest;
@@ -165,6 +165,19 @@ is($mc-&gt;incr(&quot;x&quot;), 1, &quot;Second incr call is one&quot;);
 is($mc-&gt;incr(&quot;x&quot;, 211), 212, &quot;Adding 211 gives you 212&quot;);
 is($mc-&gt;incr(&quot;x&quot;, 2**33), 8589934804, &quot;Blast the 32bit border&quot;);
 
+# diag &quot;Issue 48 - incrementing plain text.&quot;;
+{
+    $mc-&gt;set(&quot;issue48&quot;, &quot;text&quot;, 0, 0);
+    my $rv =()= eval { $mc-&gt;incr('issue48'); };
+    ok($@ &amp;&amp; $@-&gt;delta_badval, &quot;Expected invalid value when incrementing text.&quot;);
+    $check-&gt;('issue48', 0, &quot;text&quot;);
+
+    my $rv =()= eval { $mc-&gt;decr('issue48'); };
+    ok($@ &amp;&amp; $@-&gt;delta_badval, &quot;Expected invalid value when decrementing text.&quot;);
+    $check-&gt;('issue48', 0, &quot;text&quot;);
+}
+
+
 # diag &quot;Test decrement&quot;;
 $mc-&gt;flush;
 is($mc-&gt;incr(&quot;x&quot;, undef, 5), 5, &quot;Initial value&quot;);
@@ -646,10 +659,13 @@ package MC::Error;
 use strict;
 use warnings;
 
-use constant ERR_UNKNOWN_CMD =&gt; 0x81;
-use constant ERR_NOT_FOUND   =&gt; 0x1;
-use constant ERR_EXISTS      =&gt; 0x2;
-use constant ERR_TOO_BIG     =&gt; 0x3;
+use constant ERR_UNKNOWN_CMD  =&gt; 0x81;
+use constant ERR_NOT_FOUND    =&gt; 0x1;
+use constant ERR_EXISTS       =&gt; 0x2;
+use constant ERR_TOO_BIG      =&gt; 0x3;
+use constant ERR_EINVAL       =&gt; 0x4;
+use constant ERR_NOT_STORED   =&gt; 0x5;
+use constant ERR_DELTA_BADVAL =&gt; 0x6;
 
 use overload '&quot;&quot;' =&gt; sub {
     my $self = shift;
@@ -679,5 +695,10 @@ sub too_big {
     return $self-&gt;[0] == ERR_TOO_BIG;
 }
 
+sub delta_badval {
+    my $self = shift;
+    return $self-&gt;[0] == ERR_DELTA_BADVAL;
+}
+
 # vim: filetype=perl
 </diff>
      <filename>t/binary.t</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>223a43644dcf986533b3f65179cd4181e152f9c8</id>
    </parent>
  </parents>
  <author>
    <name>Dustin Sallings</name>
    <email>dustin@spy.net</email>
  </author>
  <url>http://github.com/dustin/memcached/commit/cce46e8f092b2c57cdb94a780f67d95b65bdd762</url>
  <id>cce46e8f092b2c57cdb94a780f67d95b65bdd762</id>
  <committed-date>2009-06-29T14:17:52-07:00</committed-date>
  <authored-date>2009-06-21T00:05:54-07:00</authored-date>
  <message>New binary protocol error for bad stored value in incr/decr (issue48)</message>
  <tree>d39e89d005304907604c176f3c78716fe6ffc183</tree>
  <committer>
    <name>Trond Norbye</name>
    <email>Trond.Norbye@sun.com</email>
  </committer>
</commit>
