@@ -45,7 +45,7 @@ int codec_set_kdf_iter(sqlite3* db, int nDb, int kdf_iter, int for_ctx) {
4545 if (pDb -> pBt ) {
4646 codec_ctx * ctx ;
4747 sqlite3pager_get_codec (pDb -> pBt -> pBt -> pPager , (void * * ) & ctx );
48- return sqlcipher_codec_ctx_set_kdf_iter (ctx , kdf_iter , for_ctx );
48+ if ( ctx ) return sqlcipher_codec_ctx_set_kdf_iter (ctx , kdf_iter , for_ctx );
4949 }
5050 return SQLITE_ERROR ;
5151}
@@ -57,7 +57,7 @@ int codec_set_fast_kdf_iter(sqlite3* db, int nDb, int kdf_iter, int for_ctx) {
5757 if (pDb -> pBt ) {
5858 codec_ctx * ctx ;
5959 sqlite3pager_get_codec (pDb -> pBt -> pBt -> pPager , (void * * ) & ctx );
60- return sqlcipher_codec_ctx_set_fast_kdf_iter (ctx , kdf_iter , for_ctx );
60+ if ( ctx ) return sqlcipher_codec_ctx_set_fast_kdf_iter (ctx , kdf_iter , for_ctx );
6161 }
6262 return SQLITE_ERROR ;
6363}
@@ -86,14 +86,14 @@ int codec_set_use_hmac(sqlite3* db, int nDb, int use) {
8686 int rc ;
8787 codec_ctx * ctx ;
8888 sqlite3pager_get_codec (pDb -> pBt -> pBt -> pPager , (void * * ) & ctx );
89-
90- rc = sqlcipher_codec_ctx_set_use_hmac (ctx , use );
91- if (rc != SQLITE_OK ) return rc ;
92-
93- /* since the use of hmac has changed, the page size may also change */
94- /* Note: before forcing the page size we need to force pageSizeFixed to 0, else
89+ if (ctx ) {
90+ rc = sqlcipher_codec_ctx_set_use_hmac (ctx , use );
91+ if (rc != SQLITE_OK ) return rc ;
92+ /* since the use of hmac has changed, the page size may also change */
93+ /* Note: before forcing the page size we need to force pageSizeFixed to 0, else
9594 sqliteBtreeSetPageSize will block the change */
96- return codec_set_btree_to_codec_pagesize (db , pDb , ctx );
95+ return codec_set_btree_to_codec_pagesize (db , pDb , ctx );
96+ }
9797 }
9898 return SQLITE_ERROR ;
9999}
@@ -107,10 +107,11 @@ int codec_set_page_size(sqlite3* db, int nDb, int size) {
107107 codec_ctx * ctx ;
108108 sqlite3pager_get_codec (pDb -> pBt -> pBt -> pPager , (void * * ) & ctx );
109109
110- rc = sqlcipher_codec_ctx_set_pagesize (ctx , size );
111- if (rc != SQLITE_OK ) return rc ;
112-
113- return codec_set_btree_to_codec_pagesize (db , pDb , ctx );
110+ if (ctx ) {
111+ rc = sqlcipher_codec_ctx_set_pagesize (ctx , size );
112+ if (rc != SQLITE_OK ) return rc ;
113+ return codec_set_btree_to_codec_pagesize (db , pDb , ctx );
114+ }
114115 }
115116 return SQLITE_ERROR ;
116117}
@@ -128,7 +129,7 @@ int codec_set_cipher_name(sqlite3* db, int nDb, const char *cipher_name, int for
128129 if (pDb -> pBt ) {
129130 codec_ctx * ctx ;
130131 sqlite3pager_get_codec (pDb -> pBt -> pBt -> pPager , (void * * ) & ctx );
131- return sqlcipher_codec_ctx_set_cipher (ctx , cipher_name , for_ctx );
132+ if ( ctx ) return sqlcipher_codec_ctx_set_cipher (ctx , cipher_name , for_ctx );
132133 }
133134 return SQLITE_ERROR ;
134135}
@@ -139,7 +140,7 @@ int codec_set_pass_key(sqlite3* db, int nDb, const void *zKey, int nKey, int for
139140 if (pDb -> pBt ) {
140141 codec_ctx * ctx ;
141142 sqlite3pager_get_codec (pDb -> pBt -> pBt -> pPager , (void * * ) & ctx );
142- return sqlcipher_codec_ctx_set_pass (ctx , zKey , nKey , for_ctx );
143+ if ( ctx ) return sqlcipher_codec_ctx_set_pass (ctx , zKey , nKey , for_ctx );
143144 }
144145 return SQLITE_ERROR ;
145146}
0 commit comments