Browse Source

610281 - fix coverity Defect Type: Control flow issues

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

11834 DEADCODE Triaged Unassigned Bug Minor Fix Required
write_function() ds/ldap/servers/slapd/daemon.c

Comment:
The location of checking for sentbytes is not correct.
 Execution cannot reach this statement "if (sentbytes < count){ {...".
 1724            } else if (sentbytes < count) {
 1725                LDAPDebug(LDAP_DEBUG_CONNS,
It should not be "else" of checking for "bytes".
Moving the check after "else if (sentbytes > count)".
Noriko Hosoi 15 years ago
parent
commit
25dfa7cf81
1 changed files with 9 additions and 8 deletions
  1. 9 8
      ldap/servers/slapd/daemon.c

+ 9 - 8
ldap/servers/slapd/daemon.c

@@ -1693,7 +1693,7 @@ write_function( int ignore, const void *buffer, int count, struct lextiof_socket
     int fd = PR_FileDesc2NativeHandle((PRFileDesc *)handle);
 
     if (handle == SLAPD_INVALID_SOCKET) {
-		PR_SetError(PR_NOT_SOCKET_ERROR, EBADF);
+        PR_SetError(PR_NOT_SOCKET_ERROR, EBADF);
     } else {
         while (1) {
             if (slapd_poll(handle, SLAPD_POLLOUT) < 0) { /* error */
@@ -1721,13 +1721,8 @@ write_function( int ignore, const void *buffer, int count, struct lextiof_socket
                           fd, prerr, slapd_pr_strerror(prerr));
                 PR_SetError(PR_PIPE_ERROR, EPIPE);
                 break;
-            } else if (sentbytes < count) {
-                LDAPDebug(LDAP_DEBUG_CONNS,
-                          "PR_Write(%d) - wrote only %d bytes (expected %d bytes) - 0 (EOF)\n", /* disconnected */
-                          fd, sentbytes, count);
-                PR_SetError(PR_PIPE_ERROR, EPIPE);
-                break;
-            }
+            } 
+
             if (sentbytes == count) { /* success */
                 return count;
             } else if (sentbytes > count) { /* too many bytes */
@@ -1736,6 +1731,12 @@ write_function( int ignore, const void *buffer, int count, struct lextiof_socket
                           fd, sentbytes, count);
                 PR_SetError(PR_BUFFER_OVERFLOW_ERROR, EMSGSIZE);
                 break;
+            } else if (sentbytes < count) {
+                LDAPDebug(LDAP_DEBUG_CONNS,
+                          "PR_Write(%d) - wrote only %d bytes (expected %d bytes) - 0 (EOF)\n", /* disconnected */
+                          fd, sentbytes, count);
+                PR_SetError(PR_PIPE_ERROR, EPIPE);
+                break;
             }
         }
     }