--- main/db.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) Index: b/main/db.c =================================================================== --- a/main/db.c +++ b/main/db.c @@ -183,6 +183,12 @@ int ast_db_get(const char *family, const res = astdb->get(astdb, &key, &data, 0); + if (!res && data.size) { + ((char *)data.data)[data.size - 1] = '\0'; + /* Make sure that we don't write too much to the dst pointer or we don't read too much from the source pointer */ + ast_copy_string(value, data.data, (valuelen > data.size) ? data.size : valuelen); + } + ast_mutex_unlock(&dblock); /* Be sure to NULL terminate our data either way */ @@ -192,11 +198,7 @@ int ast_db_get(const char *family, const #if 0 printf("Got value of size %d\n", data.size); #endif - if (data.size) { - ((char *)data.data)[data.size - 1] = '\0'; - /* Make sure that we don't write too much to the dst pointer or we don't read too much from the source pointer */ - ast_copy_string(value, data.data, (valuelen > data.size) ? data.size : valuelen); - } else { + if (!data.size) { ast_log(LOG_NOTICE, "Strange, empty value for /%s/%s\n", family, keys); } }