@@ -389,10 +389,9 @@ static int sqlcipher_cipher_ctx_set_keyspec(cipher_ctx *ctx, const unsigned char
389389
390390 ctx -> keyspec [0 ] = 'x' ;
391391 ctx -> keyspec [1 ] = '\'' ;
392- ctx -> keyspec [ctx -> keyspec_sz - 1 ] = '\'' ;
393392 cipher_bin2hex (key , key_sz , ctx -> keyspec + 2 );
394393 cipher_bin2hex (salt , salt_sz , ctx -> keyspec + (key_sz * 2 ) + 2 );
395-
394+ ctx -> keyspec [ ctx -> keyspec_sz - 1 ] = '\'' ;
396395 return SQLITE_OK ;
397396}
398397
@@ -980,15 +979,9 @@ int sqlcipher_codec_ctx_migrate(codec_ctx *ctx) {
980979 memcpy (key , ctx -> read_ctx -> pass , ctx -> read_ctx -> pass_sz );
981980
982981 if (db_filename ){
983-
982+ const char * commands [ 4 ];
984983 char * attach_command = sqlite3_mprintf ("ATTACH DATABASE '%s-migrated' as migrate KEY '%s';" ,
985984 db_filename , key );
986- const char * commands [] = {
987- upgrade_4k_format == 1 ? pragma_4k_kdf_iter : "" ,
988- upgrade_1x_format == 1 ? pragma_hmac_off : "" ,
989- attach_command ,
990- "SELECT sqlcipher_export('migrate');" ,
991- };
992985
993986 int rc = sqlcipher_check_connection (db_filename , key , key_sz , "" );
994987 if (rc == SQLITE_OK ){
@@ -1019,7 +1012,11 @@ int sqlcipher_codec_ctx_migrate(codec_ctx *ctx) {
10191012 goto handle_error ;
10201013 }
10211014
1022-
1015+ commands [0 ] = upgrade_4k_format == 1 ? pragma_4k_kdf_iter : "" ;
1016+ commands [1 ] = upgrade_1x_format == 1 ? pragma_hmac_off : "" ;
1017+ commands [2 ] = attach_command ;
1018+ commands [3 ] = "SELECT sqlcipher_export('migrate');" ;
1019+
10231020 for (command_idx = 0 ; command_idx < (sizeof (commands )/sizeof (commands [0 ])); command_idx ++ ){
10241021 const char * command = commands [command_idx ];
10251022 if (strcmp (command , "" ) == 0 ){
0 commit comments