From e767924756756993ea08c1636ee6d1af3e2775b0 Mon Sep 17 00:00:00 2001
From: Mark Reynolds <mreynolds@redhat.com>
Date: Tue, 4 Jun 2013 13:25:22 -0400
Subject: [PATCH 90/99] Coverity Fixes (Part 2)
11674 - logically dead code (collate.c)
11675 - logically dead code (windows_protocol_util.c)
11676 - logically dead code (index.c)
11677 - logically dead code (ldbm_entryrdn.c)
11678 - logically dead code (ldbm_entryrdn.c)
11680 - logically dead code (ldbm_search.c)
11681 - Dead default in switch (seq.c)
11683 - logically dead code (bind.c)
11684 - logically dead code (connection.c)
11686 - Dead default in switch (log.c)
11687 - Dead default in switch (log.c)
11688 - Dead default in switch (log.c)
11689 - Dead default in switch (log.c)
11690 - Dead default in switch (log.c)
11691 - Dead default in switch (log.c)
https://bugzilla.redhat.com/show_bug.cgi?id=970221
Reviewed by: nhosoi(Thanks!)
(cherry picked from commit db673270e9a01e48adb22d94e676f25a223f407b)
(cherry picked from commit 41a882743c7c21575ed5365fe0484bc8d96edc6f)
---
ldap/servers/plugins/collation/collate.c | 24 +++++------
.../plugins/replication/windows_protocol_util.c | 9 ++---
ldap/servers/slapd/back-ldbm/index.c | 17 ++++----
ldap/servers/slapd/back-ldbm/ldbm_entryrdn.c | 24 +++--------
ldap/servers/slapd/back-ldbm/ldbm_search.c | 2 +-
ldap/servers/slapd/back-ldbm/seq.c | 2 -
ldap/servers/slapd/bind.c | 2 +-
ldap/servers/slapd/log.c | 46 +++++-----------------
8 files changed, 40 insertions(+), 86 deletions(-)
diff --git a/ldap/servers/plugins/collation/collate.c b/ldap/servers/plugins/collation/collate.c
index 240da70..2a73ee1 100644
--- a/ldap/servers/plugins/collation/collate.c
+++ b/ldap/servers/plugins/collation/collate.c
@@ -437,11 +437,7 @@ collation_indexer_create (const char* oid)
profile->variant == NULL);
UErrorCode err = U_ZERO_ERROR;
if ( ! is_default) {
- if (locale) {
- PR_smprintf_free(locale);
- locale = NULL;
- }
- err = s_newNamedLocaleFromComponents(&locale,
+ err = s_newNamedLocaleFromComponents(&locale,
profile->language,
profile->country,
profile->variant);
@@ -460,27 +456,27 @@ collation_indexer_create (const char* oid)
ucol_setAttribute (coll, UCOL_STRENGTH, profile->strength, &err);
if (err != U_ZERO_ERROR && err != U_USING_FALLBACK_WARNING
&& (err != U_USING_DEFAULT_WARNING || !is_default)) {
- LDAPDebug (LDAP_DEBUG_ANY, "collation_indexer_create: could not "
+ LDAPDebug (LDAP_DEBUG_ANY, "collation_indexer_create: could not "
"set the collator strength for oid %s to %d: err %d\n",
oid, profile->strength, err);
}
ucol_setAttribute (coll, UCOL_DECOMPOSITION_MODE, profile->decomposition, &err);
if (err != U_ZERO_ERROR && err != U_USING_FALLBACK_WARNING
&& (err != U_USING_DEFAULT_WARNING || !is_default)) {
- LDAPDebug (LDAP_DEBUG_ANY, "collation_indexer_create: could not "
+ LDAPDebug (LDAP_DEBUG_ANY, "collation_indexer_create: could not "
"set the collator decomposition mode for oid %s to %d: err %d\n",
oid, profile->decomposition, err);
}
etc->collator = coll;
for (id = collation_id; *id; ++id) {
- if ((*id)->profile == profile) {
- break; /* found the 'official' id */
- }
+ if ((*id)->profile == profile) {
+ break; /* found the 'official' id */
+ }
}
- if (!*id) {
- LDAPDebug (LDAP_DEBUG_ANY, "collation_indexer_create: id not found\n", 0, 0, 0);
- goto error;
- }
+ if (!*id) {
+ LDAPDebug (LDAP_DEBUG_ANY, "collation_indexer_create: id not found\n", 0, 0, 0);
+ goto error;
+ }
ix->ix_etc = etc;
ix->ix_oid = (*id)->oid;
diff --git a/ldap/servers/plugins/replication/windows_protocol_util.c b/ldap/servers/plugins/replication/windows_protocol_util.c
index 1bafa9a..0b3c575 100644
--- a/ldap/servers/plugins/replication/windows_protocol_util.c
+++ b/ldap/servers/plugins/replication/windows_protocol_util.c
@@ -4190,7 +4190,7 @@ windows_generate_update_mods(Private_Repl_Protocol *prp,Slapi_Entry *remote_entr
windows_is_remote_entry_user_or_group(remote_entry,&is_user,&is_group);
}
- for (rc = slapi_entry_first_attr(remote_entry, &attr); rc == 0;
+ for (rc = slapi_entry_first_attr(remote_entry, &attr); rc == 0;
rc = slapi_entry_next_attr(remote_entry, attr, &attr))
{
int is_present_local = 0;
@@ -4201,7 +4201,6 @@ windows_generate_update_mods(Private_Repl_Protocol *prp,Slapi_Entry *remote_entr
int is_guid = 0;
int mapdn = 0;
-
slapi_attr_get_type( attr, &type );
slapi_attr_get_valueset(attr,&vs);
@@ -4360,7 +4359,7 @@ windows_generate_update_mods(Private_Repl_Protocol *prp,Slapi_Entry *remote_entr
"windows_generate_update_mods: no restricted local values found for "
"local attribute %s in local entry %s for remote attribute "
"%s in remote entry %s\n",
- local_type ? local_type : "NULL",
+ local_type,
slapi_entry_get_dn(local_entry),
type ? type : "NULL",
slapi_entry_get_dn(remote_entry));
@@ -4372,7 +4371,7 @@ windows_generate_update_mods(Private_Repl_Protocol *prp,Slapi_Entry *remote_entr
"windows_generate_update_mods: no local values found for "
"local attribute %s in local entry %s for remote attribute "
"%s in remote entry %s\n",
- local_type ? local_type : "NULL",
+ local_type,
slapi_entry_get_dn(local_entry),
type ? type : "NULL",
slapi_entry_get_dn(remote_entry));
@@ -4384,7 +4383,7 @@ windows_generate_update_mods(Private_Repl_Protocol *prp,Slapi_Entry *remote_entr
"windows_generate_update_mods: could not map the values in "
"local attribute %s in local entry %s for remote attribute "
"%s in remote entry %s\n",
- local_type ? local_type : "NULL",
+ local_type,
slapi_entry_get_dn(local_entry),
type ? type : "NULL",
slapi_entry_get_dn(remote_entry));
diff --git a/ldap/servers/slapd/back-ldbm/index.c b/ldap/servers/slapd/back-ldbm/index.c
index 62a58a7..7769791 100644
--- a/ldap/servers/slapd/back-ldbm/index.c
+++ b/ldap/servers/slapd/back-ldbm/index.c
@@ -649,18 +649,17 @@ index_add_mods(
mods[i]->mod_op |= LDAP_MOD_IGNORE;
}
}
- if (mods_valueArray) {
- rc = index_addordel_values_sv( be,
- mods[i]->mod_type,
- mods_valueArray, NULL,
- id, BE_INDEX_ADD, txn );
- if (rc) {
- ldbm_nasty(errmsg, 1042, rc);
- goto error;
- }
+ if(mods_valueArray[0]){
+ rc = index_addordel_values_sv( be, mods[i]->mod_type,
+ mods_valueArray, NULL,
+ id, BE_INDEX_ADD, txn );
} else {
rc = 0;
}
+ if (rc) {
+ ldbm_nasty(errmsg, 1042, rc);
+ goto error;
+ }
}
}
break;
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_entryrdn.c b/ldap/servers/slapd/back-ldbm/ldbm_entryrdn.c
index 4329b16..156461b 100644
--- a/ldap/servers/slapd/back-ldbm/ldbm_entryrdn.c
+++ b/ldap/servers/slapd/back-ldbm/ldbm_entryrdn.c
@@ -809,14 +809,8 @@ entryrdn_rename_subtree(backend *be,
renamedata.data = (void *)oldsupelem;
}
} else {
- if (mynewsupsdn) {
- renamedata.ulen = renamedata.size = newsupelemlen;
- renamedata.data = (void *)newsupelem;
- } else {
- /* never comes here */
- rc = -1;
- goto bail;
- }
+ renamedata.ulen = renamedata.size = newsupelemlen;
+ renamedata.data = (void *)newsupelem;
}
rc = _entryrdn_put_data(cursor, &key, &renamedata, RDN_INDEX_PARENT, db_txn);
if (rc) {
@@ -901,16 +895,10 @@ entryrdn_rename_subtree(backend *be,
renamedata.data = (void *)targetelem;
}
} else {
- if (mynewsrdn) {
- memset(&renamedata, 0, sizeof(renamedata));
- renamedata.ulen = renamedata.size = newelemlen;
- renamedata.data = (void *)newelem;
- renamedata.flags = DB_DBT_USERMEM;
- } else {
- /* never comes here */
- rc = -1;
- goto bail;
- }
+ memset(&renamedata, 0, sizeof(renamedata));
+ renamedata.ulen = renamedata.size = newelemlen;
+ renamedata.data = (void *)newelem;
+ renamedata.flags = DB_DBT_USERMEM;
}
rc = _entryrdn_put_data(cursor, &key, &renamedata, RDN_INDEX_CHILD, db_txn);
if (rc) {
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_search.c b/ldap/servers/slapd/back-ldbm/ldbm_search.c
index 670f627..e68b897 100644
--- a/ldap/servers/slapd/back-ldbm/ldbm_search.c
+++ b/ldap/servers/slapd/back-ldbm/ldbm_search.c
@@ -573,7 +573,7 @@ ldbm_back_search( Slapi_PBlock *pb )
/* This candidate list is for vlv, no need for sort only. */
switch (vlv_search_build_candidate_list(pb, basesdn, &vlv_rc,
sort_control,
- (vlv ? &vlv_request_control : NULL),
+ &vlv_request_control,
&candidates, &vlv_response_control)) {
case VLV_ACCESS_DENIED:
return ldbm_back_search_cleanup(pb, li, sort_control,
diff --git a/ldap/servers/slapd/back-ldbm/seq.c b/ldap/servers/slapd/back-ldbm/seq.c
index 1435ba2..ab473bd 100644
--- a/ldap/servers/slapd/back-ldbm/seq.c
+++ b/ldap/servers/slapd/back-ldbm/seq.c
@@ -221,8 +221,6 @@ ldbm_back_seq( Slapi_PBlock *pb )
}
}
break;
- default:
- PR_ASSERT(0);
}
dbc->c_close(dbc);
diff --git a/ldap/servers/slapd/bind.c b/ldap/servers/slapd/bind.c
index e92add5..ec874cc 100644
--- a/ldap/servers/slapd/bind.c
+++ b/ldap/servers/slapd/bind.c
@@ -178,7 +178,7 @@ do_bind( Slapi_PBlock *pb )
/* check that the dn is formatted correctly */
rc = slapi_dn_syntax_check(pb, rawdn, 1);
if (rc) { /* syntax check failed */
- op_shared_log_error_access(pb, "BIND", rawdn?rawdn:"",
+ op_shared_log_error_access(pb, "BIND", rawdn,
"strict: invalid bind dn");
send_ldap_result(pb, LDAP_INVALID_DN_SYNTAX,
NULL, "invalid bind dn", 0, NULL);
diff --git a/ldap/servers/slapd/log.c b/ldap/servers/slapd/log.c
index 9b3f640..72a918b 100644
--- a/ldap/servers/slapd/log.c
+++ b/ldap/servers/slapd/log.c
@@ -1011,8 +1011,6 @@ log_set_rotationsynchour(const char *attrname, char *rhour_str, int logtype, cha
fe_cfg->auditlog_rotationsynchour = rhour;
LOG_AUDIT_UNLOCK_WRITE();
break;
- default:
- rv = 1;
}
return rv;
@@ -1065,8 +1063,6 @@ log_set_rotationsyncmin(const char *attrname, char *rmin_str, int logtype, char
loginfo.log_audit_rotationsyncclock = log_get_rotationsyncclock( loginfo.log_audit_rotationsynchour, rmin );
LOG_AUDIT_UNLOCK_WRITE();
break;
- default:
- rv = 1;
}
return rv;
@@ -1122,8 +1118,6 @@ log_set_rotationtime(const char *attrname, char *rtime_str, int logtype, char *r
loginfo.log_audit_rotationtime = rtime;
runit = loginfo.log_audit_rotationunit;
break;
- default:
- rv = 1;
}
/* find out the rotation unit we have se right now */
@@ -1151,19 +1145,17 @@ log_set_rotationtime(const char *attrname, char *rtime_str, int logtype, char *r
fe_cfg->accesslog_rotationtime = rtime;
loginfo.log_access_rotationtime_secs = value;
LOG_ACCESS_UNLOCK_WRITE();
- break;
+ break;
case SLAPD_ERROR_LOG:
fe_cfg->errorlog_rotationtime = rtime;
- loginfo.log_error_rotationtime_secs = value;
- LOG_ERROR_UNLOCK_WRITE();
- break;
+ loginfo.log_error_rotationtime_secs = value;
+ LOG_ERROR_UNLOCK_WRITE();
+ break;
case SLAPD_AUDIT_LOG:
fe_cfg->auditlog_rotationtime = rtime;
- loginfo.log_audit_rotationtime_secs = value;
- LOG_AUDIT_UNLOCK_WRITE();
- break;
- default:
- rv = 1;
+ loginfo.log_audit_rotationtime_secs = value;
+ LOG_AUDIT_UNLOCK_WRITE();
+ break;
}
return rv;
}
@@ -1219,8 +1211,6 @@ int log_set_rotationtimeunit(const char *attrname, char *runit, int logtype, cha
LOG_AUDIT_LOCK_WRITE( );
origvalue = loginfo.log_audit_rotationtime;
break;
- default:
- rv = 1;
}
if (strcasecmp(runit, "month") == 0) {
@@ -1270,8 +1260,6 @@ int log_set_rotationtimeunit(const char *attrname, char *runit, int logtype, cha
fe_cfg->auditlog_rotationunit = slapi_ch_strdup ( runit );
LOG_AUDIT_UNLOCK_WRITE();
break;
- default:
- rv = 1;
}
return rv;
}
@@ -1321,9 +1309,6 @@ log_set_maxdiskspace(const char *attrname, char *maxdiskspace_str, int logtype,
LOG_AUDIT_LOCK_WRITE( );
mlogsize = loginfo.log_audit_maxlogsize;
break;
- default:
- rv = 1;
- mlogsize = -1;
}
maxdiskspace = (PRInt64)s_maxdiskspace * LOG_MB_IN_BYTES;
if (maxdiskspace < 0) {
@@ -1357,11 +1342,6 @@ log_set_maxdiskspace(const char *attrname, char *maxdiskspace_str, int logtype,
}
LOG_AUDIT_UNLOCK_WRITE();
break;
- default:
- PR_snprintf( errorbuf, SLAPI_DSE_RETURNTEXT_SIZE,
- "%s: invalid log type (%d) for setting maximum disk space: %d MB\n",
- attrname, logtype, s_maxdiskspace);
- rv = LDAP_OPERATIONS_ERROR;
}
return rv;
@@ -1581,10 +1561,6 @@ log_set_expirationtimeunit(const char *attrname, char *expunit, int logtype, cha
rsecs = loginfo.log_audit_rotationtime_secs;
exptimeunitp = &(loginfo.log_audit_exptimeunit);
break;
- default:
- rv = 1;
- exptime = -1;
- rsecs = -1;
}
value = -1;
@@ -1634,8 +1610,6 @@ log_set_expirationtimeunit(const char *attrname, char *expunit, int logtype, cha
fe_cfg->auditlog_exptimeunit = slapi_ch_strdup ( expunit );
LOG_AUDIT_UNLOCK_WRITE();
break;
- default:
- rv = 1;
}
return rv;
@@ -1756,8 +1730,8 @@ slapd_log_audit_proc (
char *buffer,
int buf_len)
{
- int err;
if ( (loginfo.log_audit_state & LOGGING_ENABLED) && (loginfo.log_audit_file != NULL) ){
+ int err;
LOG_AUDIT_LOCK_WRITE( );
if (log__needrotation(loginfo.log_audit_fdes,
SLAPD_AUDIT_LOG) == LOG_ROTATE) {
@@ -4176,9 +4150,9 @@ static void log_append_buffer2(time_t tnl, LogBufferInfo *lbi, char *msg1, size_
static void log_flush_buffer(LogBufferInfo *lbi, int type, int sync_now)
{
slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig();
- int err = 0;
-
+
if (type == SLAPD_ACCESS_LOG) {
+ int err = 0;
/* It is only safe to flush once any other threads which are copying are finished */
while (lbi->refcount > 0) {
--
1.8.1.4