Fix potential buffer overrun

Change-Id: Ic0914d025e8dc2e880dc7cf6b90a3e5c99a7ad0c
Reviewed-on: http://review.couchbase.org/31524
Reviewed-by: Trond Norbye <trond.norbye@gmail.com>
Tested-by: Trond Norbye <trond.norbye@gmail.com>