Commit 830f58ff authored by Matthieu Dorier's avatar Matthieu Dorier
Browse files

better handling of size mismatch in get() calls

parent 7dd4849a
...@@ -188,6 +188,9 @@ int sdskv_put_multi(sdskv_provider_handle_t provider, ...@@ -188,6 +188,9 @@ int sdskv_put_multi(sdskv_provider_handle_t provider,
* If value is NULL, the call will be equivalent * If value is NULL, the call will be equivalent
* to sdskv_length and put the length of the value in *vsize. * to sdskv_length and put the length of the value in *vsize.
* *
* If the call returns SDSKV_ERR_SIZE, the value will be
* unchanged but the vsize will be set to the required size.
*
* @param[in] provider provider handle * @param[in] provider provider handle
* @param[in] db_id database id of the target database * @param[in] db_id database id of the target database
* @param[in] key key to lookup * @param[in] key key to lookup
......
...@@ -480,7 +480,16 @@ class client { ...@@ -480,7 +480,16 @@ class client {
s = length(db, key); s = length(db, key);
object_resize(value, s); object_resize(value, s);
} }
get(db, object_data(key), object_size(key), object_data(value), &s); try {
get(db, object_data(key), object_size(key), object_data(value), &s);
} catch(exception& ex) {
if(ex.error() == SDSKV_ERR_SIZE) {
object_resize(value, s);
get(db, object_data(key), object_size(key), object_data(value), &s);
} else {
throw;
}
}
object_resize(value, s); object_resize(value, s);
return true; return true;
} }
......
...@@ -609,7 +609,7 @@ int sdskv_get(sdskv_provider_handle_t provider, ...@@ -609,7 +609,7 @@ int sdskv_get(sdskv_provider_handle_t provider,
ret = out.ret; ret = out.ret;
*vsize = (hg_size_t)out.value.size; *vsize = (hg_size_t)out.value.size;
if (out.value.size > 0) { if (out.value.size > 0 && out.ret == SDSKV_SUCCESS) {
memcpy(value, out.value.data, out.value.size); memcpy(value, out.value.data, out.value.size);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment