base: Fix warnings

This commit is contained in:
Nicolas Williams
2021-03-27 22:44:57 -05:00
parent 69b3c5368c
commit ed0fd1263a
5 changed files with 38 additions and 30 deletions

View File

@@ -275,11 +275,12 @@ bsearch_common(const char *buf, size_t sz, const char *key,
ret = 0;
if (val_len && value) {
/* Avoid strndup() so we don't need libroken here yet */
*value = malloc(val_len + 1);
if (!*value)
ret = errno;
(void) memcpy(*value, &buf[val_start], val_len);
(*value)[val_len] = '\0';
if ((*value = malloc(val_len + 1))) {
(void) memcpy(*value, &buf[val_start], val_len);
(*value)[val_len] = '\0';
} else {
ret = errno;
}
}
break;
}
@@ -708,6 +709,10 @@ _bsearch_file(bsearch_file_handle bfh, const char *key,
if (reads)
*reads = 0;
if (value)
*value = NULL;
if (loops)
*loops = 0;
/* If whole file is in memory then search that and we're done */
if (bfh->file_sz == bfh->cache_sz)
@@ -715,11 +720,6 @@ _bsearch_file(bsearch_file_handle bfh, const char *key,
/* Else block-wise binary search */
if (value)
*value = NULL;
if (loops)
*loops = 0;
l = 0;
r = (bfh->file_sz / bfh->page_sz) + 1;
for (level = 0, page = r >> 1; page >= l && page < r ; level++) {
@@ -851,7 +851,7 @@ stdb_copy_value(void *db, heim_string_t table, heim_data_t key,
{
bsearch_file_handle bfh = db;
const char *k;
char *v;
char *v = NULL;
heim_data_t value;
int ret;
@@ -869,6 +869,8 @@ stdb_copy_value(void *db, heim_string_t table, heim_data_t key,
else
k = (const char *)heim_data_get_ptr(key);
ret = _bsearch_file(bfh, k, &v, NULL, NULL, NULL);
if (ret == 0 && v == NULL)
ret = -1; /* Quiet lint */
if (ret != 0) {
if (ret > 0 && error)
*error = heim_error_create(ret, "%s", strerror(ret));