Fixed strings returned by get to be null terminated (request by Cal
[m6w6/libmemcached] / lib / memcached_get.c
index c7c21d1ee43ad7518700d1c6f026ca1323dcd62a..4894b2a05ef32334a9f26029057412ee5ac2dda7 100644 (file)
@@ -96,6 +96,13 @@ static char *memcached_value_fetch(memcached_st *ptr, char *key, size_t *key_len
 
       value_ptr= value;
       read_length= 0;
+      /* 
+        We read the \r\n into the string since not doing so is more 
+        cycles then the waster of memory to do so.
+
+        We are null terminating through, which will most likely make
+        some people lazy about using the return length.
+      */
       to_read= (*value_length) + 2;
 
       read_length= memcached_io_read(ptr, server_key,
@@ -107,6 +114,9 @@ static char *memcached_value_fetch(memcached_st *ptr, char *key, size_t *key_len
         goto read_error;
       }
 
+      value[*value_length]= 0;
+      value[(*value_length) + 1]= 0;
+
       return value;
     }
   }