From f94de982b69e79e8a27193e3b765ff37d66f1ada Mon Sep 17 00:00:00 2001 From: Greg Hudson Date: Wed, 3 Nov 2010 17:32:11 +0000 Subject: [PATCH] Simplify kdb_db2's open_db() a little further, avoiding a suspicious switch fallthrough. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@24508 dc483132-0cff-0310-8789-dd5450dbe970 --- src/plugins/kdb/db2/kdb_db2.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/plugins/kdb/db2/kdb_db2.c b/src/plugins/kdb/db2/kdb_db2.c index a5ec2d01d..36969584a 100644 --- a/src/plugins/kdb/db2/kdb_db2.c +++ b/src/plugins/kdb/db2/kdb_db2.c @@ -309,13 +309,14 @@ open_db(krb5_db2_context *dbc, char *fname, int flags, int mode) hashi.lorder = 0; hashi.nelem = 1; + /* Try our best guess at the database type. */ db = dbopen(fname, flags, mode, dbc->hashfirst ? DB_HASH : DB_BTREE, dbc->hashfirst ? (void *) &hashi : (void *) &bti); - if (db != NULL) { - free(fname); - return db; - } + if (db != NULL) + goto done; + + /* If that was wrong, retry with the other type. */ switch (errno) { #ifdef EFTYPE case EFTYPE: @@ -324,12 +325,15 @@ open_db(krb5_db2_context *dbc, char *fname, int flags, int mode) db = dbopen(fname, flags, mode, dbc->hashfirst ? DB_BTREE : DB_HASH, dbc->hashfirst ? (void *) &bti : (void *) &hashi); + /* If that worked, update our guess for next time. */ if (db != NULL) dbc->hashfirst = !dbc->hashfirst; - default: - free(fname); - return db; + break; } + +done: + free(fname); + return db; } /* Initialize the lock file and policy database fields of the DB2 context -- 2.26.2