<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - False positive in for-loop in C: Analyzer says that loop needn't be executed, assert() preceding the loop is ignored"
   href="http://llvm.org/bugs/show_bug.cgi?id=16541">16541</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>False positive in for-loop in C: Analyzer says that loop needn't be executed, assert() preceding the loop is ignored
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.3
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Static Analyzer
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>kremenek@apple.com
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>pspacek@redhat.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Version:
clang 3.3rc3 (I used package clang-3.3-0.6.rc3.fc19.x86_64 in Fedora 19, i.e.
3.3rc3, source package is
<a href="http://kojipkgs.fedoraproject.org//packages/llvm/3.3/0.6.rc3.fc19/src/llvm-3.3-0.6.rc3.fc19.src.rpm">http://kojipkgs.fedoraproject.org//packages/llvm/3.3/0.6.rc3.fc19/src/llvm-3.3-0.6.rc3.fc19.src.rpm</a>)


Following function call generates false positive:

4290    CHECK(ldap_pool_getconnection(inst->pool, &conn));
←    Within the expansion of the macro 'CHECK':     
a    Calling 'ldap_pool_getconnection'
b    Returning from 'ldap_pool_getconnection'

4291    
4292    /* Try to connect. */
4293    while (conn->handle == NULL) {
←    Access to field 'handle' results in a dereference of a null pointer
(loaded from variable 'conn')



The called function contains for-loop and the assertion:

3504    #include <assert.h>
3505    
3506    static isc_result_t
3507    ldap_pool_getconnection(ldap_pool_t *pool, ldap_connection_t ** conn)
3508    {
3509        ldap_connection_t *ldap_conn = NULL;
3510        unsigned int i;
3511        isc_result_t result;
3512    
3513        REQUIRE(pool != NULL);
3514        REQUIRE(conn != NULL && *conn == NULL);
3515        assert(pool->connections > 0);    
←    Within the expansion of the macro 'assert':     
(seriously, there is nothing after the colon!)

3516    
3517        ldap_conn = *conn;
←    Null pointer value stored to 'ldap_conn'    

3518        CHECK(semaphore_wait_timed(&pool->conn_semaphore));
←    Within the expansion of the macro 'CHECK':     
Assuming 'result' is equal to 0

3519        for (i = 0; i < pool->connections; i++) {
←    Loop condition is false. Execution continues on line 3525    

3520            ldap_conn = pool->conns[i];
3521            if (isc_mutex_trylock(&ldap_conn->lock) == ISC_R_SUCCESS)
3522                break;
3523        }
3524    
3525    RUNTIME_CHECK(ldap_conn != NULL);
3526    
3527        *conn = ldap_conn;
←    Null pointer value stored to 'conn'    

3528    
3529    cleanup:
3530        if (result != ISC_R_SUCCESS) {
←    Taking false branch    

3531            log_error("timeout in ldap_pool_getconnection(): try to raise "
3532              "'connections' parameter; potential deadlock?");
3533        }
3534        return result;
3535    }

You can compile
<a href="https://fedorahosted.org/released/bind-dyndb-ldap/bind-dyndb-ldap-3.4.tar.bz2">https://fedorahosted.org/released/bind-dyndb-ldap/bind-dyndb-ldap-3.4.tar.bz2</a>
yourself and see the bug in natura.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>