From 04ba254a9c8b8be2aec1794bece362bc819acffc Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Thu, 11 Oct 2007 14:55:37 -0700 Subject: [PATCH] Fixed strings returned by get to be null terminated (request by Cal Heldenbrand) --- ChangeLog | 3 +++ lib/memcached_get.c | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/ChangeLog b/ChangeLog index 58ba0402..eb5ebc9e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +0.6 + * get value returns are now null terminated (request by Cal Heldenbrand) + 0.5 Tue Oct 9 00:22:25 PDT 2007 * Ruby maintainer mentioned TCP_NODELAY patch he had added. Added this to C library as well. (Eric Hodel drbrain@segment7.net) diff --git a/lib/memcached_get.c b/lib/memcached_get.c index c7c21d1e..4894b2a0 100644 --- a/lib/memcached_get.c +++ b/lib/memcached_get.c @@ -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; } } -- 2.30.2