Jelajahi Sumber

610281 - fix coverity Defect Type: Control flow issues

https://bugzilla.redhat.com/show_bug.cgi?id=610281

11806 DEADCODE Triaged Unassigned Bug Moderate Fix Required
agmt_set_last_init_status() ds/ldap/servers/plugins/replication/repl5_agmt.c

Comment:
macro NSDS50_REPL_REPLICA_READY is 0
repl5.h:#define NSDS50_REPL_REPLICA_READY 0x00 /* Replica ready, go ahead */

Because of this if expression:
1991 else if (replrc != 0)
"Replica acquired successfully" never be set to last_init_status.
Removed (replrc == NSDS50_REPL_REPLICA_READY) checking from the
else if (replrc != 0) clause and added "Replica acquired successfully"
to the string to print message since replrc == NSDS50_REPL_REPLICA_READY
there.

11807 DEADCODE Triaged Unassigned Bug Moderate Fix Required
agmt_set_last_update_status() ds/ldap/servers/plugins/replication/repl5_agmt.c

Comment:
macro NSDS50_REPL_REPLICA_READY is 0
repl5.h:#define NSDS50_REPL_REPLICA_READY 0x00 /* Replica ready, go ahead */

Because of this if expression:
1991 else if (replrc != 0)
"Replica acquired successfully" never be set to last_update_status.
Removed (replrc == NSDS50_REPL_REPLICA_READY) checking from the
else if (replrc != 0) clause and added "Replica acquired successfully"
to the string to print message since replrc == NSDS50_REPL_REPLICA_READY
there.
Noriko Hosoi 15 tahun lalu
induk
melakukan
2c2b3ecea9
1 mengubah file dengan 20 tambahan dan 22 penghapusan
  1. 20 22
      ldap/servers/plugins/replication/repl5_agmt.c

+ 20 - 22
ldap/servers/plugins/replication/repl5_agmt.c

@@ -1921,14 +1921,10 @@ agmt_set_last_update_status (Repl_Agmt *ra, int ldaprc, int replrc, const char *
 							replmsg ? " - " : "", replmsg ? replmsg : "");
 			}
 		}
+		/* ldaprc == LDAP_SUCCESS */
 		else if (replrc != 0)
 		{
-			if (replrc == NSDS50_REPL_REPLICA_READY)
-			{
-				PR_snprintf(ra->last_update_status, STATUS_LEN, "%d %s",
-					ldaprc, "Replica acquired successfully");
-			}
-			else if (replrc == NSDS50_REPL_REPLICA_BUSY)
+			if (replrc == NSDS50_REPL_REPLICA_BUSY)
 			{
 				PR_snprintf(ra->last_update_status, STATUS_LEN,
 					"%d Can't acquire busy replica", replrc ); 
@@ -1941,8 +1937,8 @@ agmt_set_last_update_status (Repl_Agmt *ra, int ldaprc, int replrc, const char *
 			else if (replrc == NSDS50_REPL_DISABLED)
 			{
 				PR_snprintf(ra->last_update_status, STATUS_LEN, "%d Incremental update aborted: "
-                                            "Replication agreement for %s\n can not be updated while the replica is disabled.\n"
-                                            "(If the suffix is disabled you must enable it then restart the server for replication to take place).",
+					"Replication agreement for %s\n can not be updated while the replica is disabled.\n"
+					"(If the suffix is disabled you must enable it then restart the server for replication to take place).",
 					replrc, ra->long_name ? ra->long_name : "a replica");
 				/* Log into the errors log, as "ra->long_name" is not accessible from the caller */
 				slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
@@ -1959,11 +1955,14 @@ agmt_set_last_update_status (Repl_Agmt *ra, int ldaprc, int replrc, const char *
 					message?" - ":"",message?message:"");
 			}
 		}
-		else if (message != NULL)
+		else if (message != NULL) /* replrc == NSDS50_REPL_REPLICA_READY == 0 */
 		{
-			PR_snprintf(ra->last_update_status, STATUS_LEN, "%d %s", ldaprc, message);
+			PR_snprintf(ra->last_update_status, STATUS_LEN, 
+						"%d Replica acquired successfully: %s",
+						ldaprc, message);
 		}
-		else { /* agmt_set_last_update_status(0,0,NULL) to reset agmt */
+		else
+		{ /* agmt_set_last_update_status(0,0,NULL) to reset agmt */
 			PR_snprintf(ra->last_update_status, STATUS_LEN, "%d", ldaprc);
 		}
 	}
@@ -1999,14 +1998,10 @@ agmt_set_last_init_status (Repl_Agmt *ra, int ldaprc, int replrc, const char *me
 							replmsg ? " - " : "", replmsg ? replmsg : "");
 			}
 		}
+		/* ldaprc == LDAP_SUCCESS */
 		else if (replrc != 0)
 		{
-			if (replrc == NSDS50_REPL_REPLICA_READY)
-			{
-				PR_snprintf(ra->last_init_status, STATUS_LEN, "%d %s",
-					ldaprc, "Replica acquired successfully");
-			}
-			else if (replrc == NSDS50_REPL_REPLICA_RELEASE_SUCCEEDED)
+			if (replrc == NSDS50_REPL_REPLICA_RELEASE_SUCCEEDED)
 			{
 				PR_snprintf(ra->last_init_status, STATUS_LEN, "%d %s",
 					ldaprc, "Replication session successful");
@@ -2014,8 +2009,8 @@ agmt_set_last_init_status (Repl_Agmt *ra, int ldaprc, int replrc, const char *me
 			else if (replrc == NSDS50_REPL_DISABLED)
 			{
 				PR_snprintf(ra->last_init_status, STATUS_LEN, "%d Total update aborted: "
-                                            "Replication agreement for %s\n can not be updated while the replica is disabled.\n"
-                                            "(If the suffix is disabled you must enable it then restart the server for replication to take place).",
+					"Replication agreement for %s\n can not be updated while the replica is disabled.\n"
+					"(If the suffix is disabled you must enable it then restart the server for replication to take place).",
 					replrc, ra->long_name ? ra->long_name : "a replica");
 				/* Log into the errors log, as "ra->long_name" is not accessible from the caller */
 				slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
@@ -2032,11 +2027,14 @@ agmt_set_last_init_status (Repl_Agmt *ra, int ldaprc, int replrc, const char *me
 					message?" - ":"",message?message:"");
 			}
 		}
-		else if (message != NULL)
+		else if (message != NULL) /* replrc == NSDS50_REPL_REPLICA_READY == 0 */
 		{
-			PR_snprintf(ra->last_init_status, STATUS_LEN, "%d %s", ldaprc, message);
+			PR_snprintf(ra->last_init_status, STATUS_LEN,
+						"%d Replica acquired successfully: %s", 
+						ldaprc, message);
 		}
-		else { /* agmt_set_last_init_status(0,0,NULL) to reset agmt */
+		else
+		{ /* agmt_set_last_init_status(0,0,NULL) to reset agmt */
 			PR_snprintf(ra->last_init_status, STATUS_LEN, "%d", ldaprc);
 		}
 	}