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

View File

@@ -83,7 +83,8 @@ struct tls_values {
static HEIMDAL_THREAD_LOCAL struct tls_values values; static HEIMDAL_THREAD_LOCAL struct tls_values values;
#define DEAD_KEY ((void *)8) static char dead_key;
#define DEAD_KEY ((void *)&dead_key)
void void
heim_w32_service_thread_detach(void *unused) heim_w32_service_thread_detach(void *unused)

View File

@@ -630,7 +630,6 @@ heim_expand_path_tokensv(heim_context context,
break; break;
extra_tokens[i] = strdup(s); extra_tokens[i] = strdup(s);
if (extra_tokens[i++] == NULL) { if (extra_tokens[i++] == NULL) {
va_end(ap);
free_extra_tokens(extra_tokens); free_extra_tokens(extra_tokens);
return heim_enomem(context); return heim_enomem(context);
} }
@@ -639,7 +638,6 @@ heim_expand_path_tokensv(heim_context context,
s = ""; s = "";
extra_tokens[i] = strdup(s); extra_tokens[i] = strdup(s);
if (extra_tokens[i] == NULL) { if (extra_tokens[i] == NULL) {
va_end(ap);
free_extra_tokens(extra_tokens); free_extra_tokens(extra_tokens);
return heim_enomem(context); return heim_enomem(context);
} }

View File

@@ -205,10 +205,13 @@ open_syslog(heim_context context,
heim_log_facility *facility, int min, int max, heim_log_facility *facility, int min, int max,
const char *sev, const char *fac) const char *sev, const char *fac)
{ {
struct _heimdal_syslog_data *sd = malloc(sizeof(*sd)); struct _heimdal_syslog_data *sd;
heim_error_code ret;
int i; int i;
if (sd == NULL) if (facility == NULL)
return EINVAL;
if ((sd = calloc(1, sizeof(*sd))) == NULL)
return heim_enomem(context); return heim_enomem(context);
i = find_value(sev, syslogvals); i = find_value(sev, syslogvals);
if (i == -1) if (i == -1)
@@ -219,8 +222,11 @@ open_syslog(heim_context context,
i = LOG_AUTH; i = LOG_AUTH;
sd->priority |= i; sd->priority |= i;
roken_openlog(facility->program, LOG_PID | LOG_NDELAY, i); roken_openlog(facility->program, LOG_PID | LOG_NDELAY, i);
return heim_addlog_func(context, facility, min, max, ret = heim_addlog_func(context, facility, min, max, log_syslog,
log_syslog, close_syslog, sd); close_syslog, sd);
if (ret)
free(sd);
return ret;
} }
struct file_data { struct file_data {
@@ -248,7 +254,7 @@ log_file(heim_context context, const char *timestr, const char *msg, void *data)
size_t i = 0; size_t i = 0;
size_t j; size_t j;
if (logf == NULL || (f->disp & FILEDISP_REOPEN)) { if (f->filename && (logf == NULL || (f->disp & FILEDISP_REOPEN))) {
int flags = O_WRONLY|O_APPEND; int flags = O_WRONLY|O_APPEND;
int fd; int fd;
@@ -339,9 +345,9 @@ open_file(heim_context context, heim_log_facility *fac, int min, int max,
if (ret) { if (ret) {
free(fd->filename); free(fd->filename);
free(fd); free(fd);
} } else if (disp & FILEDISP_KEEPOPEN) {
if (disp & FILEDISP_KEEPOPEN)
log_file(context, NULL, NULL, fd); log_file(context, NULL, NULL, fd);
}
return ret; return ret;
} }
@@ -385,7 +391,7 @@ heim_addlog_dest(heim_context context, heim_log_facility *f, const char *orig)
p++; p++;
} }
if (strcmp(p, "STDERR") == 0) { if (strcmp(p, "STDERR") == 0) {
ret = open_file(context, f, min, max, NULL, NULL, stderr, ret = open_file(context, f, min, max, NULL, "a", stderr,
FILEDISP_KEEPOPEN, 0); FILEDISP_KEEPOPEN, 0);
} else if (strcmp(p, "CONSOLE") == 0) { } else if (strcmp(p, "CONSOLE") == 0) {
/* XXX WIN32 */ /* XXX WIN32 */
@@ -609,10 +615,7 @@ __attribute__ ((__format__ (__printf__, 3, 0)))
heim_error_code heim_error_code
heim_have_debug(heim_context context, int level) heim_have_debug(heim_context context, int level)
{ {
heim_log_facility *fac; return (context != NULL && heim_get_debug_dest(context) != NULL);
return (context != NULL &&
(fac = heim_get_debug_dest(context)) != NULL);
} }
heim_error_code heim_error_code

View File

@@ -590,34 +590,37 @@ add_dso_plugins_load_fn(heim_context context,
heim_error_code ret; heim_error_code ret;
heim_array_t plugins; heim_array_t plugins;
heim_plugin_load_t load_fn; heim_plugin_load_t load_fn;
char *sym; char *sym = NULL;
size_t i; size_t i;
heim_get_instance_func_t get_instance; heim_get_instance_func_t get_instance;
size_t n_ftables; size_t n_ftables;
heim_plugin_common_ftable_cp *ftables; heim_plugin_common_ftable_cp *ftables;
if (asprintf(&sym, "%s_plugin_load", caller->name) == -1) if (asprintf(&sym, "%s_plugin_load", caller->name) == -1 || sym == NULL)
return NULL; return NULL;
/* suppress error here because we may be looking for a different plugin type */ /* suppress error here because we may be looking for a different plugin type */
load_fn = (heim_plugin_load_t)dlsym(dsohandle, sym); load_fn = (heim_plugin_load_t)dlsym(dsohandle, sym);
free(sym);
if (load_fn == NULL) { if (load_fn == NULL) {
heim_debug(context, 15, "Symbol %s not found in %s", sym, dsopath); heim_debug(context, 15, "Symbol %s not found in %s", sym, dsopath);
free(sym);
return NULL; return NULL;
} }
ret = load_fn(pcontext, &get_instance, &n_ftables, &ftables); ret = load_fn(pcontext, &get_instance, &n_ftables, &ftables);
if (ret) { if (ret) {
heim_warn(context, ret, "plugin %s failed to load", dsopath); heim_warn(context, ret, "plugin %s failed to load", dsopath);
free(sym);
/* fallback to loading structure directly */ /* fallback to loading structure directly */
return add_dso_plugin_struct(context, pcontext, dsopath, return add_dso_plugin_struct(context, pcontext, dsopath,
dsohandle, caller->name); dsohandle, caller->name);
} }
if (!validate_plugin_deps(context, caller, dsopath, get_instance)) if (!validate_plugin_deps(context, caller, dsopath, get_instance)) {
free(sym);
return NULL; return NULL;
}
plugins = heim_array_create(); plugins = heim_array_create();
@@ -639,6 +642,7 @@ add_dso_plugins_load_fn(heim_context context,
} }
heim_debug(context, 15, "DSO %s loaded (%s)", dsopath, sym); heim_debug(context, 15, "DSO %s loaded (%s)", dsopath, sym);
free(sym);
return plugins; return plugins;
} }
#endif /* HAVE_DLOPEN */ #endif /* HAVE_DLOPEN */