SQLite User Forum

Suspicious 'address of array 'pParse->writeMask' will always evaluate to true' warning
Login

Suspicious 'address of array 'pParse->writeMask' will always evaluate to true' warning

(1) By Karen Arutyunov (karen.arutyunov) on 2023-01-23 20:17:30 [source]

While packaging libsqlite3 3.39.4 for build2 toolchain we compile amalgamated sqlite3.c with -DSQLITE_MAX_ATTACHED=125 option. Compiling with clang 13.0.0 on Linux ends up with the following warning:

  sqlite3.c:157895:15: warning: address of array pParse->writeMask will always evaluate to 'true' [-Wpointer-bool-conversion]
    if( pParse->writeMask ){
    ~~  ~~~~~~~~^~~~~~~~~
  1 warning generated.

The referenced code looks quite suspicious:

  if( pParse->writeMask ){
    for(i=0; i<nDb; i++){
      sqlite3BeginWriteOperation(pParse, 0, i);
    }
  }

Shouldn't it be as follows or similar:

  if( DbMaskNonZero(pParse->writeMask) ){
    for(i=0; i<nDb; i++){
      sqlite3BeginWriteOperation(pParse, 0, i);
    }
  }

The issue also appears in the latest released version 3.40.1 and can be reproduced with the following commands:

$ cd sqlite-autoconf-3400100
$ mkdir build
$ cd build
$ CC="clang" CFLAGS="-DSQLITE_MAX_ATTACHED=125" ../configure
$ make

(2) By Richard Hipp (drh) on 2023-01-23 20:47:04 in reply to 1 [link] [source]

Fixed. This bug is mostly harmless. I doubt you'll be able to come up with a test case that causes SQLite to malfunction because of it. But it is good to fix it, nevertheless. Thanks for reporting it.