Unreachable code in pager.c

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Unreachable code in pager.c

F.W.A. van Leeuwen
While cross-compiling sqlite3.2.1, my Blackfin C compiler gives the
following warning:

".\src\pager.c", line 1342: cc0111: {D} warning: statement is unreachable
    assert( rc==SQLITE_OK );

The context is:

<begin code snippet>
  /* This loop terminates either when the readJournalHdr() call returns
  ** SQLITE_DONE or an IO error occurs. */
  while( 1 ){

    // CODE OMITTED WITH NO break;

    /* rc = sqlite3OsSeek(&pPager->jfd, JOURNAL_HDR_SZ(pPager)); */
    if( rc!=SQLITE_OK ) goto end_playback;
 
    /* Copy original pages out of the journal and back into the database
file.
    */
    for(i=0; i<nRec; i++){
      rc = pager_playback_one_page(pPager, &pPager->jfd, 1);
      if( rc!=SQLITE_OK ){
        if( rc==SQLITE_DONE ){
          rc = SQLITE_OK;
          pPager->journalOff = szJ;
          break;
        }else{
          goto end_playback;
        }
      }
    }
  }

  /* Pages that have been written to the journal but never synced
  ** where not restored by the loop above.  We have to restore those
  ** pages by reading them back from the original database.
  */
  assert( rc==SQLITE_OK );
  pager_reload_cache(pPager);

end_playback:
<end code snippet>

I think the compiler is right. I am not familiar with the sqlite3 source
code, but the break at line 1330 breaks the for() loop at line 1324, NOT
the while() loop at line 1281.  Is that as it is intended, or is it a
potential bug?

Best regards,
Frank.
Reply | Threaded
Open this post in threaded view
|

Re: Unreachable code in pager.c

Jay Sprenkle
On 6/23/05, F.W.A. van Leeuwen <[hidden email]> wrote:

> While cross-compiling sqlite3.2.1, my Blackfin C compiler gives the
> following warning:
>
> ".\src\pager.c", line 1342: cc0111: {D} warning: statement is unreachable
>     assert( rc==SQLITE_OK );
>
> The context is:
>
> <begin code snippet>
>   /* This loop terminates either when the readJournalHdr() call returns
>   ** SQLITE_DONE or an IO error occurs. */
>   while( 1 ){
>
>     // CODE OMITTED WITH NO break;
>
>     /* rc = sqlite3OsSeek(&pPager->jfd, JOURNAL_HDR_SZ(pPager)); */
>     if( rc!=SQLITE_OK ) goto end_playback;
>
>     /* Copy original pages out of the journal and back into the database
> file.
>     */
>     for(i=0; i<nRec; i++){
>       rc = pager_playback_one_page(pPager, &pPager->jfd, 1);
>       if( rc!=SQLITE_OK ){
>         if( rc==SQLITE_DONE ){
>           rc = SQLITE_OK;
>           pPager->journalOff = szJ;
>           break;
>         }else{
>           goto end_playback;
>         }
>       }
>     }
>   }
>
>   /* Pages that have been written to the journal but never synced
>   ** where not restored by the loop above.  We have to restore those
>   ** pages by reading them back from the original database.
>   */
>   assert( rc==SQLITE_OK );
>   pager_reload_cache(pPager);
>
> end_playback:
> <end code snippet>
>
> I think the compiler is right. I am not familiar with the sqlite3 source
> code, but the break at line 1330 breaks the for() loop at line 1324, NOT
> the while() loop at line 1281.  Is that as it is intended, or is it a
> potential bug?

The for loop can terminate after i>=nRec. I'm not sure that's possible
in practice
or not though.
Reply | Threaded
Open this post in threaded view
|

Re: Unreachable code in pager.c

F.W.A. van Leeuwen
The (inner) for() loop will terminate when i>=nRec.
But it is inside an (outer) while(1) loop.
So the code below the while(1) is still unreachable.

Frank
Reply | Threaded
Open this post in threaded view
|

Re: Unreachable code in pager.c

D. Richard Hipp
In reply to this post by F.W.A. van Leeuwen
On Thu, 2005-06-23 at 15:52 +0200, F.W.A. van Leeuwen wrote:
> I think the compiler is right. I am not familiar with the sqlite3 source
> code, but the break at line 1330 breaks the for() loop at line 1324, NOT
> the while() loop at line 1281.  Is that as it is intended, or is it a
> potential bug?
>

We do coverage testing from time to time using
gcov.  And things like this would really stand out.

I'll rerun the coverage tests in a few days and see
what pops up.
--
D. Richard Hipp <[hidden email]>

Reply | Threaded
Open this post in threaded view
|

Re: Unreachable code in pager.c

Jay Sprenkle
In reply to this post by F.W.A. van Leeuwen
I counted the parens, and you're right. It's definitely not reachable.


> I think the compiler is right. I am not familiar with the sqlite3 source
> code, but the break at line 1330 breaks the for() loop at line 1324, NOT
> the while() loop at line 1281.  Is that as it is intended, or is it a
> potential bug?