Skip to content

Commit

Permalink
Avoid side effects in assert expressions
Browse files Browse the repository at this point in the history
asserts may be compiled out with -DNDEBUG, so it's wrong to use an
assert expression with an important side effect.

(We also have scores of side-effecting asserts in test programs, but
those are less important and can be dealt with separately.)

(cherry picked from commit 221cd4a)

ticket: 7542 (new)
version_fixed: 1.10.4
status: resolved
  • Loading branch information
greghudson authored and tlyu committed Jan 11, 2013
1 parent 8e2ca00 commit 4a5475f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/lib/apputils/net-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,10 @@ static void
do_network_reconfig(verto_ctx *ctx, verto_ev *ev)
{
struct connection *conn = verto_get_private(ev);
assert(loop_setup_network(ctx, conn->handle, conn->prog) == 0);
if (loop_setup_network(ctx, conn->handle, conn->prog) != 0) {
krb5_klog_syslog(LOG_ERR, _("Failed to reconfigure network, exiting"));
verto_break(ctx);
}
}

static int
Expand Down
3 changes: 2 additions & 1 deletion src/lib/crypto/krb/cf2.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ krb5_c_fx_cf2_simple(krb5_context context,
return KRB5_BAD_ENCTYPE;
out_enctype_num = k1->enctype;
assert(out != NULL);
assert((out_enctype = find_enctype(out_enctype_num)) != NULL);
out_enctype = find_enctype(out_enctype_num);
assert(out_enctype != NULL);
if (out_enctype->prf == NULL) {
if (context)
krb5int_set_error(&(context->err), KRB5_CRYPTO_INTERNAL,
Expand Down
12 changes: 8 additions & 4 deletions src/util/et/com_err.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,10 @@ et_old_error_hook_func set_com_err_hook (et_old_error_hook_func new_proc)
et_old_error_hook_func x;

/* Broken initialization? What can we do? */
assert(com_err_finish_init() == 0);
assert(com_err_lock_hook_handle() == 0);
if (com_err_finish_init() != 0)
abort();
if (com_err_lock_hook_handle() != 0)
abort();
x = com_err_hook;
com_err_hook = new_proc;
k5_mutex_unlock(&com_err_hook_lock);
Expand All @@ -167,8 +169,10 @@ et_old_error_hook_func reset_com_err_hook ()
et_old_error_hook_func x;

/* Broken initialization? What can we do? */
assert(com_err_finish_init() == 0);
assert(com_err_lock_hook_handle() == 0);
if (com_err_finish_init() != 0)
abort();
if (com_err_lock_hook_handle() != 0)
abort();
x = com_err_hook;
com_err_hook = NULL;
k5_mutex_unlock(&com_err_hook_lock);
Expand Down

0 comments on commit 4a5475f

Please sign in to comment.