/ Check-in [71b6f507]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Merge all recent trunk fixes and enhancements into the apple-osx branch.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | apple-osx
Files: files | file ages | folders
SHA1: 71b6f507f1c5feb897b8162c468ecf2547a3d50e
User & Date: drh 2015-04-01 16:13:35
Context
2015-04-08
12:47
Merge in all version 3.8.9 changes from trunk. check-in: 30121870 user: drh tags: apple-osx
2015-04-01
16:13
Merge all recent trunk fixes and enhancements into the apple-osx branch. check-in: 71b6f507 user: drh tags: apple-osx
13:21
Improved detection and suppression of endless loops in clearDatabasePage(). check-in: 30011ad2 user: drh tags: trunk
2015-03-30
23:52
Merge the latest trunk enhancements, and especially the fix for the infinite loop on a DROP TABLE in a corrupt database, into the apple-osx branch. check-in: 4d42bf5e user: drh tags: apple-osx
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to Makefile.in.

  1068   1068   	$(INSTALL) -d $(DESTDIR)$(includedir)
  1069   1069   	$(INSTALL) -m 0644 sqlite3.h $(DESTDIR)$(includedir)
  1070   1070   	$(INSTALL) -m 0644 $(TOP)/src/sqlite3ext.h $(DESTDIR)$(includedir)
  1071   1071   	$(INSTALL) -d $(DESTDIR)$(pkgconfigdir)
  1072   1072   	$(INSTALL) -m 0644 sqlite3.pc $(DESTDIR)$(pkgconfigdir)
  1073   1073   
  1074   1074   pkgIndex.tcl:
  1075         -	echo 'package ifneeded sqlite3 $(RELEASE) [list load [file join \$dir libtclsqlite3.so] Tclsqlite3]' > $@
         1075  +	echo 'package ifneeded sqlite3 $(RELEASE) [list load $(TCLLIBDIR)/libtclsqlite3$(SHLIB_SUFFIX) sqlite3]' > $@
  1076   1076   tcl_install:	lib_install libtclsqlite3.la pkgIndex.tcl
  1077   1077   	$(INSTALL) -d $(DESTDIR)$(TCLLIBDIR)/sqlite3
  1078   1078   	$(LTINSTALL) libtclsqlite3.la $(DESTDIR)$(TCLLIBDIR)/sqlite3
  1079   1079   	rm -f $(DESTDIR)$(TCLLIBDIR)/sqlite3/libtclsqlite3.la $(DESTDIR)$(TCLLIBDIR)/sqlite3/libtclsqlite3.a
  1080   1080   	$(INSTALL) -m 0644 pkgIndex.tcl $(DESTDIR)$(TCLLIBDIR)/sqlite3
  1081   1081   
  1082   1082   clean:	

Changes to Makefile.msc.

  1153   1153   sqlite3.exe:	$(TOP)\src\shell.c $(SHELL_CORE_DEP) $(LIBRESOBJS) sqlite3.h
  1154   1154   	$(LTLINK) $(SHELL_COMPILE_OPTS) $(READLINE_FLAGS) $(TOP)\src\shell.c \
  1155   1155   		/link /pdb:sqlite3sh.pdb $(LTLINKOPTS) $(SHELL_LINK_OPTS) $(LTLIBPATHS) $(LIBRESOBJS) $(LIBREADLINE) $(LTLIBS) $(TLIBS)
  1156   1156   
  1157   1157   mptester.exe:	$(TOP)\mptest\mptest.c $(SHELL_CORE_DEP) $(LIBRESOBJS) sqlite3.h
  1158   1158   	$(LTLINK) $(SHELL_COMPILE_OPTS) $(TOP)\mptest\mptest.c \
  1159   1159   		/link $(LTLINKOPTS) $(LTLIBPATHS) $(SHELL_LINK_OPTS) $(LIBRESOBJS) $(LIBREADLINE) $(LTLIBS) $(TLIBS)
         1160  +
         1161  +MPTEST1 = mptester mptest.db $(TOP)/mptest/crash01.test --repeat 20
         1162  +MPTEST2 = mptester mptest.db $(TOP)/mptest/multiwrite01.test --repeat 20
         1163  +
         1164  +mptest:	mptester.exe
         1165  +	del /Q mptest.db 2>NUL
         1166  +	$(MPTEST1) --journalmode DELETE
         1167  +	$(MPTEST2) --journalmode WAL
         1168  +	$(MPTEST1) --journalmode WAL
         1169  +	$(MPTEST2) --journalmode PERSIST
         1170  +	$(MPTEST1) --journalmode PERSIST
         1171  +	$(MPTEST2) --journalmode TRUNCATE
         1172  +	$(MPTEST1) --journalmode TRUNCATE
         1173  +	$(MPTEST2) --journalmode DELETE
  1160   1174   
  1161   1175   # This target creates a directory named "tsrc" and fills it with
  1162   1176   # copies of all of the C source code and header files needed to
  1163   1177   # build on the target system.  Some of the C source code and header
  1164   1178   # files are automatically generated.  This target takes care of
  1165   1179   # all that automatic generation.
  1166   1180   #

Changes to configure.

   880    880   TCL_INCLUDE_SPEC
   881    881   TCL_LIB_FILE
   882    882   TCL_LIB_FLAG
   883    883   TCL_LIB_SPEC
   884    884   TCL_STUB_LIB_FILE
   885    885   TCL_STUB_LIB_FLAG
   886    886   TCL_STUB_LIB_SPEC
          887  +TCL_SHLIB_SUFFIX
   887    888   HAVE_TCL
   888    889   TARGET_READLINE_LIBS
   889    890   TARGET_READLINE_INC
   890    891   TARGET_HAVE_READLINE
   891    892   TARGET_DEBUG
   892    893   USE_AMALGAMATION
   893    894   OPT_FEATURE_FLAGS
................................................................................
  3720   3721   { $as_echo "$as_me:$LINENO: checking the name lister ($NM) interface" >&5
  3721   3722   $as_echo_n "checking the name lister ($NM) interface... " >&6; }
  3722   3723   if test "${lt_cv_nm_interface+set}" = set; then
  3723   3724     $as_echo_n "(cached) " >&6
  3724   3725   else
  3725   3726     lt_cv_nm_interface="BSD nm"
  3726   3727     echo "int some_variable = 0;" > conftest.$ac_ext
  3727         -  (eval echo "\"\$as_me:3727: $ac_compile\"" >&5)
         3728  +  (eval echo "\"\$as_me:3728: $ac_compile\"" >&5)
  3728   3729     (eval "$ac_compile" 2>conftest.err)
  3729   3730     cat conftest.err >&5
  3730         -  (eval echo "\"\$as_me:3730: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
         3731  +  (eval echo "\"\$as_me:3731: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
  3731   3732     (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out)
  3732   3733     cat conftest.err >&5
  3733         -  (eval echo "\"\$as_me:3733: output\"" >&5)
         3734  +  (eval echo "\"\$as_me:3734: output\"" >&5)
  3734   3735     cat conftest.out >&5
  3735   3736     if $GREP 'External.*some_variable' conftest.out > /dev/null; then
  3736   3737       lt_cv_nm_interface="MS dumpbin"
  3737   3738     fi
  3738   3739     rm -f conftest*
  3739   3740   fi
  3740   3741   { $as_echo "$as_me:$LINENO: result: $lt_cv_nm_interface" >&5
................................................................................
  4948   4949   	;;
  4949   4950       esac
  4950   4951     fi
  4951   4952     rm -rf conftest*
  4952   4953     ;;
  4953   4954   *-*-irix6*)
  4954   4955     # Find out which ABI we are using.
  4955         -  echo '#line 4955 "configure"' > conftest.$ac_ext
         4956  +  echo '#line 4956 "configure"' > conftest.$ac_ext
  4956   4957     if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
  4957   4958     (eval $ac_compile) 2>&5
  4958   4959     ac_status=$?
  4959   4960     $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
  4960   4961     (exit $ac_status); }; then
  4961   4962       if test "$lt_cv_prog_gnu_ld" = yes; then
  4962   4963         case `/usr/bin/file conftest.$ac_objext` in
................................................................................
  6817   6818      # Note that $ac_compile itself does not contain backslashes and begins
  6818   6819      # with a dollar sign (not a hyphen), so the echo should work correctly.
  6819   6820      # The option is referenced via a variable to avoid confusing sed.
  6820   6821      lt_compile=`echo "$ac_compile" | $SED \
  6821   6822      -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
  6822   6823      -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
  6823   6824      -e 's:$: $lt_compiler_flag:'`
  6824         -   (eval echo "\"\$as_me:6824: $lt_compile\"" >&5)
         6825  +   (eval echo "\"\$as_me:6825: $lt_compile\"" >&5)
  6825   6826      (eval "$lt_compile" 2>conftest.err)
  6826   6827      ac_status=$?
  6827   6828      cat conftest.err >&5
  6828         -   echo "$as_me:6828: \$? = $ac_status" >&5
         6829  +   echo "$as_me:6829: \$? = $ac_status" >&5
  6829   6830      if (exit $ac_status) && test -s "$ac_outfile"; then
  6830   6831        # The compiler can only warn and ignore the option if not recognized
  6831   6832        # So say no if there are warnings other than the usual output.
  6832   6833        $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' >conftest.exp
  6833   6834        $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2
  6834   6835        if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then
  6835   6836          lt_cv_prog_compiler_rtti_exceptions=yes
................................................................................
  7156   7157      # Note that $ac_compile itself does not contain backslashes and begins
  7157   7158      # with a dollar sign (not a hyphen), so the echo should work correctly.
  7158   7159      # The option is referenced via a variable to avoid confusing sed.
  7159   7160      lt_compile=`echo "$ac_compile" | $SED \
  7160   7161      -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
  7161   7162      -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
  7162   7163      -e 's:$: $lt_compiler_flag:'`
  7163         -   (eval echo "\"\$as_me:7163: $lt_compile\"" >&5)
         7164  +   (eval echo "\"\$as_me:7164: $lt_compile\"" >&5)
  7164   7165      (eval "$lt_compile" 2>conftest.err)
  7165   7166      ac_status=$?
  7166   7167      cat conftest.err >&5
  7167         -   echo "$as_me:7167: \$? = $ac_status" >&5
         7168  +   echo "$as_me:7168: \$? = $ac_status" >&5
  7168   7169      if (exit $ac_status) && test -s "$ac_outfile"; then
  7169   7170        # The compiler can only warn and ignore the option if not recognized
  7170   7171        # So say no if there are warnings other than the usual output.
  7171   7172        $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' >conftest.exp
  7172   7173        $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2
  7173   7174        if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then
  7174   7175          lt_cv_prog_compiler_pic_works=yes
................................................................................
  7261   7262      # (2) before a word containing "conftest.", or (3) at the end.
  7262   7263      # Note that $ac_compile itself does not contain backslashes and begins
  7263   7264      # with a dollar sign (not a hyphen), so the echo should work correctly.
  7264   7265      lt_compile=`echo "$ac_compile" | $SED \
  7265   7266      -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
  7266   7267      -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
  7267   7268      -e 's:$: $lt_compiler_flag:'`
  7268         -   (eval echo "\"\$as_me:7268: $lt_compile\"" >&5)
         7269  +   (eval echo "\"\$as_me:7269: $lt_compile\"" >&5)
  7269   7270      (eval "$lt_compile" 2>out/conftest.err)
  7270   7271      ac_status=$?
  7271   7272      cat out/conftest.err >&5
  7272         -   echo "$as_me:7272: \$? = $ac_status" >&5
         7273  +   echo "$as_me:7273: \$? = $ac_status" >&5
  7273   7274      if (exit $ac_status) && test -s out/conftest2.$ac_objext
  7274   7275      then
  7275   7276        # The compiler can only warn and ignore the option if not recognized
  7276   7277        # So say no if there are warnings
  7277   7278        $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' > out/conftest.exp
  7278   7279        $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2
  7279   7280        if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then
................................................................................
  7316   7317      # (2) before a word containing "conftest.", or (3) at the end.
  7317   7318      # Note that $ac_compile itself does not contain backslashes and begins
  7318   7319      # with a dollar sign (not a hyphen), so the echo should work correctly.
  7319   7320      lt_compile=`echo "$ac_compile" | $SED \
  7320   7321      -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
  7321   7322      -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
  7322   7323      -e 's:$: $lt_compiler_flag:'`
  7323         -   (eval echo "\"\$as_me:7323: $lt_compile\"" >&5)
         7324  +   (eval echo "\"\$as_me:7324: $lt_compile\"" >&5)
  7324   7325      (eval "$lt_compile" 2>out/conftest.err)
  7325   7326      ac_status=$?
  7326   7327      cat out/conftest.err >&5
  7327         -   echo "$as_me:7327: \$? = $ac_status" >&5
         7328  +   echo "$as_me:7328: \$? = $ac_status" >&5
  7328   7329      if (exit $ac_status) && test -s out/conftest2.$ac_objext
  7329   7330      then
  7330   7331        # The compiler can only warn and ignore the option if not recognized
  7331   7332        # So say no if there are warnings
  7332   7333        $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' > out/conftest.exp
  7333   7334        $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2
  7334   7335        if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then
................................................................................
 10129  10130   else
 10130  10131     	  if test "$cross_compiling" = yes; then :
 10131  10132     lt_cv_dlopen_self=cross
 10132  10133   else
 10133  10134     lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
 10134  10135     lt_status=$lt_dlunknown
 10135  10136     cat > conftest.$ac_ext <<_LT_EOF
 10136         -#line 10136 "configure"
        10137  +#line 10137 "configure"
 10137  10138   #include "confdefs.h"
 10138  10139   
 10139  10140   #if HAVE_DLFCN_H
 10140  10141   #include <dlfcn.h>
 10141  10142   #endif
 10142  10143   
 10143  10144   #include <stdio.h>
................................................................................
 10225  10226   else
 10226  10227     	  if test "$cross_compiling" = yes; then :
 10227  10228     lt_cv_dlopen_self_static=cross
 10228  10229   else
 10229  10230     lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
 10230  10231     lt_status=$lt_dlunknown
 10231  10232     cat > conftest.$ac_ext <<_LT_EOF
 10232         -#line 10232 "configure"
        10233  +#line 10233 "configure"
 10233  10234   #include "confdefs.h"
 10234  10235   
 10235  10236   #if HAVE_DLFCN_H
 10236  10237   #include <dlfcn.h>
 10237  10238   #endif
 10238  10239   
 10239  10240   #include <stdio.h>
................................................................................
 12810  12811       eval "TCL_LIB_FILE=\"${TCL_LIB_FILE}\""
 12811  12812       eval "TCL_LIB_FLAG=\"${TCL_LIB_FLAG}\""
 12812  12813       eval "TCL_LIB_SPEC=\"${TCL_LIB_SPEC}\""
 12813  12814   
 12814  12815       eval "TCL_STUB_LIB_FILE=\"${TCL_STUB_LIB_FILE}\""
 12815  12816       eval "TCL_STUB_LIB_FLAG=\"${TCL_STUB_LIB_FLAG}\""
 12816  12817       eval "TCL_STUB_LIB_SPEC=\"${TCL_STUB_LIB_SPEC}\""
        12818  +
 12817  12819   
 12818  12820   
 12819  12821   
 12820  12822   
 12821  12823   
 12822  12824   
 12823  12825   

Changes to configure.ac.

   426    426       AC_SUBST(TCL_LIB_FILE)
   427    427       AC_SUBST(TCL_LIB_FLAG)
   428    428       AC_SUBST(TCL_LIB_SPEC)
   429    429       
   430    430       AC_SUBST(TCL_STUB_LIB_FILE)
   431    431       AC_SUBST(TCL_STUB_LIB_FLAG)
   432    432       AC_SUBST(TCL_STUB_LIB_SPEC)
          433  +    AC_SUBST(TCL_SHLIB_SUFFIX)
   433    434     fi
   434    435   fi
   435    436   if test "${use_tcl}" = "no" ; then
   436    437     HAVE_TCL=""
   437    438   else
   438    439     HAVE_TCL=1
   439    440   fi

Changes to main.mk.

   390    390   	$(TCCX) $(READLINE_FLAGS) -o sqlite3$(EXE)                  \
   391    391   		$(TOP)/src/shell.c                                  \
   392    392   		libsqlite3.a $(LIBREADLINE) $(TLIBS) $(THREADLIB)
   393    393   
   394    394   mptester$(EXE):	sqlite3.c $(TOP)/mptest/mptest.c
   395    395   	$(TCCX) -o $@ -I. $(TOP)/mptest/mptest.c sqlite3.c \
   396    396   		$(TLIBS) $(THREADLIB)
          397  +
          398  +MPTEST1=./mptester$(EXE) mptest.db $(TOP)/mptest/crash01.test --repeat 20
          399  +MPTEST2=./mptester$(EXE) mptest.db $(TOP)/mptest/multiwrite01.test --repeat 20
          400  +mptest:	mptester$(EXE)
          401  +	rm -f mptest.db
          402  +	$(MPTEST1) --journalmode DELETE
          403  +	$(MPTEST2) --journalmode WAL
          404  +	$(MPTEST1) --journalmode WAL
          405  +	$(MPTEST2) --journalmode PERSIST
          406  +	$(MPTEST1) --journalmode PERSIST
          407  +	$(MPTEST2) --journalmode TRUNCATE
          408  +	$(MPTEST1) --journalmode TRUNCATE
          409  +	$(MPTEST2) --journalmode DELETE
   397    410   
   398    411   sqlite3.o:	sqlite3.c
   399    412   	$(TCCX) -I. -c sqlite3.c
   400    413   
   401    414   # This target creates a directory named "tsrc" and fills it with
   402    415   # copies of all of the C source code and header files needed to
   403    416   # build on the target system.  Some of the C source code and header

Changes to mptest/mptest.c.

  1308   1308     if( zClient ){
  1309   1309       iClient = atoi(zClient);
  1310   1310       if( iClient<1 ) fatalError("illegal client number: %d\n", iClient);
  1311   1311       sqlite3_snprintf(sizeof(g.zName), g.zName, "%05d.client%02d",
  1312   1312                        GETPID(), iClient);
  1313   1313     }else{
  1314   1314       if( g.iTrace>0 ){
         1315  +      printf("BEGIN: %s", argv[0]);
         1316  +      for(i=1; i<argc; i++) printf(" %s", argv[i]);
         1317  +      printf("\n");
  1315   1318         printf("With SQLite " SQLITE_VERSION " " SQLITE_SOURCE_ID "\n" );
  1316   1319         for(i=0; (zCOption = sqlite3_compileoption_get(i))!=0; i++){
  1317   1320           printf("-DSQLITE_%s\n", zCOption);
  1318   1321         }
  1319   1322         fflush(stdout);
  1320   1323       }
  1321   1324       iClient =  0;
  1322   1325       unlink(g.zDbFile);
  1323   1326       openFlags |= SQLITE_OPEN_CREATE;
  1324   1327     }
  1325   1328     rc = sqlite3_open_v2(g.zDbFile, &g.db, openFlags, g.zVfs);
  1326   1329     if( rc ) fatalError("cannot open [%s]", g.zDbFile);
         1330  +  if( zJMode ){
         1331  +#if defined(_WIN32)
         1332  +    if( sqlite3_stricmp(zJMode,"persist")==0
         1333  +     || sqlite3_stricmp(zJMode,"truncate")==0
         1334  +    ){
         1335  +      printf("Changing journal mode to DELETE from %s", zJMode);
         1336  +      zJMode = "DELETE";
         1337  +    }
         1338  +#endif
         1339  +    runSql("PRAGMA journal_mode=%Q;", zJMode);
         1340  +  }
  1327   1341     sqlite3_enable_load_extension(g.db, 1);
  1328   1342     sqlite3_busy_handler(g.db, busyHandler, 0);
  1329   1343     sqlite3_create_function(g.db, "vfsname", 0, SQLITE_UTF8, 0,
  1330   1344                             vfsNameFunc, 0, 0);
  1331   1345     sqlite3_create_function(g.db, "eval", 1, SQLITE_UTF8, 0,
  1332   1346                             evalFunc, 0, 0);
  1333   1347     g.iTimeout = DEFAULT_TIMEOUT;
................................................................................
  1351   1365     }else{
  1352   1366       sqlite3_stmt *pStmt;
  1353   1367       int iTimeout;
  1354   1368       if( n==0 ){
  1355   1369         fatalError("missing script filename");
  1356   1370       }
  1357   1371       if( n>1 ) unrecognizedArguments(argv[0], n, argv+2);
  1358         -    if( zJMode ) runSql("PRAGMA journal_mode=%Q;", zJMode);
  1359   1372       runSql(
  1360   1373         "DROP TABLE IF EXISTS task;\n"
  1361   1374         "DROP TABLE IF EXISTS counters;\n"
  1362   1375         "DROP TABLE IF EXISTS client;\n"
  1363   1376         "CREATE TABLE task(\n"
  1364   1377         "  id INTEGER PRIMARY KEY,\n"
  1365   1378         "  name TEXT,\n"
................................................................................
  1405   1418       sqlite3_finalize(pStmt);
  1406   1419     }
  1407   1420     sqlite3_close(g.db);
  1408   1421     maybeClose(g.pLog);
  1409   1422     maybeClose(g.pErrLog);
  1410   1423     if( iClient==0 ){
  1411   1424       printf("Summary: %d errors out of %d tests\n", g.nError, g.nTest);
         1425  +    printf("END: %s", argv[0]);
         1426  +    for(i=1; i<argc; i++) printf(" %s", argv[i]);
         1427  +    printf("\n");
  1412   1428     }
  1413   1429     return g.nError>0;
  1414   1430   }

Changes to src/btree.c.

  1961   1961   #if !defined(SQLITE_OMIT_SHARED_CACHE) && !defined(SQLITE_OMIT_DISKIO)
  1962   1962     /*
  1963   1963     ** If this Btree is a candidate for shared cache, try to find an
  1964   1964     ** existing BtShared object that we can share with
  1965   1965     */
  1966   1966     if( isTempDb==0 && (isMemdb==0 || (vfsFlags&SQLITE_OPEN_URI)!=0) ){
  1967   1967       if( vfsFlags & SQLITE_OPEN_SHAREDCACHE ){
         1968  +      int nFilename = sqlite3Strlen30(zFilename)+1;
  1968   1969         int nFullPathname = pVfs->mxPathname+1;
  1969         -      char *zFullPathname = sqlite3Malloc(nFullPathname);
         1970  +      char *zFullPathname = sqlite3Malloc(MAX(nFullPathname,nFilename));
  1970   1971         MUTEX_LOGIC( sqlite3_mutex *mutexShared; )
         1972  +
  1971   1973         p->sharable = 1;
  1972   1974         if( !zFullPathname ){
  1973   1975           sqlite3_free(p);
  1974   1976           return SQLITE_NOMEM;
  1975   1977         }
  1976   1978         if( isMemdb ){
  1977         -        memcpy(zFullPathname, zFilename, sqlite3Strlen30(zFilename)+1);
         1979  +        memcpy(zFullPathname, zFilename, nFilename);
  1978   1980         }else{
  1979   1981           rc = sqlite3OsFullPathname(pVfs, zFilename,
  1980   1982                                      nFullPathname, zFullPathname);
  1981   1983           if( rc ){
  1982   1984             sqlite3_free(zFullPathname);
  1983   1985             sqlite3_free(p);
  1984   1986             return rc;
................................................................................
  8001   8003   ){
  8002   8004     MemPage *pPage;
  8003   8005     int rc;
  8004   8006     unsigned char *pCell;
  8005   8007     int i;
  8006   8008     int hdr;
  8007   8009     u16 szCell;
  8008         -  u8 hasChildren;
  8009   8010   
  8010   8011     assert( sqlite3_mutex_held(pBt->mutex) );
  8011   8012     if( pgno>btreePagecount(pBt) ){
  8012   8013       return SQLITE_CORRUPT_BKPT;
  8013   8014     }
  8014         -
  8015   8015     rc = getAndInitPage(pBt, pgno, &pPage, 0);
  8016   8016     if( rc ) return rc;
  8017         -  hasChildren = !pPage->leaf;
  8018         -  pPage->leaf = 1;  /* Block looping if the database is corrupt */
         8017  +  if( pPage->bBusy ){
         8018  +    rc = SQLITE_CORRUPT_BKPT;
         8019  +    goto cleardatabasepage_out;
         8020  +  }
         8021  +  pPage->bBusy = 1;
  8019   8022     hdr = pPage->hdrOffset;
  8020   8023     for(i=0; i<pPage->nCell; i++){
  8021   8024       pCell = findCell(pPage, i);
  8022         -    if( hasChildren ){
         8025  +    if( !pPage->leaf ){
  8023   8026         rc = clearDatabasePage(pBt, get4byte(pCell), 1, pnChange);
  8024   8027         if( rc ) goto cleardatabasepage_out;
  8025   8028       }
  8026   8029       rc = clearCell(pPage, pCell, &szCell);
  8027   8030       if( rc ) goto cleardatabasepage_out;
  8028   8031     }
  8029         -  if( hasChildren ){
         8032  +  if( !pPage->leaf ){
  8030   8033       rc = clearDatabasePage(pBt, get4byte(&pPage->aData[hdr+8]), 1, pnChange);
  8031   8034       if( rc ) goto cleardatabasepage_out;
  8032   8035     }else if( pnChange ){
  8033   8036       assert( pPage->intKey );
  8034   8037       *pnChange += pPage->nCell;
  8035   8038     }
  8036   8039     if( freePageFlag ){
  8037   8040       freePage(pPage, &rc);
  8038   8041     }else if( (rc = sqlite3PagerWrite(pPage->pDbPage))==0 ){
  8039   8042       zeroPage(pPage, pPage->aData[hdr] | PTF_LEAF);
  8040   8043     }
  8041   8044   
  8042   8045   cleardatabasepage_out:
         8046  +  pPage->bBusy = 0;
  8043   8047     releasePage(pPage);
  8044   8048     return rc;
  8045   8049   }
  8046   8050   
  8047   8051   /*
  8048   8052   ** Delete all information from a single table in the database.  iTable is
  8049   8053   ** the page number of the root of the table.  After this routine returns,

Changes to src/btreeInt.h.

   276    276     u8 intKey;           /* True if table b-trees.  False for index b-trees */
   277    277     u8 intKeyLeaf;       /* True if the leaf of an intKey table */
   278    278     u8 noPayload;        /* True if internal intKey page (thus w/o data) */
   279    279     u8 leaf;             /* True if a leaf page */
   280    280     u8 hdrOffset;        /* 100 for page 1.  0 otherwise */
   281    281     u8 childPtrSize;     /* 0 if leaf==1.  4 if leaf==0 */
   282    282     u8 max1bytePayload;  /* min(maxLocal,127) */
          283  +  u8 bBusy;            /* Prevent endless loops on corrupt database files */
   283    284     u16 maxLocal;        /* Copy of BtShared.maxLocal or BtShared.maxLeaf */
   284    285     u16 minLocal;        /* Copy of BtShared.minLocal or BtShared.minLeaf */
   285    286     u16 cellOffset;      /* Index in aData of first cell pointer */
   286    287     u16 nFree;           /* Number of free bytes on the page */
   287    288     u16 nCell;           /* Number of cells on this page, local and ovfl */
   288    289     u16 maskPage;        /* Mask for page offset */
   289    290     u16 aiOvfl[5];       /* Insert the i-th overflow cell before the aiOvfl-th

Changes to src/os_win.c.

   193    193           DWORD, DWORD, DWORD, LPCWSTR);
   194    194   #endif /* defined(SQLITE_WIN32_HAS_WIDE) */
   195    195   
   196    196   WINBASEAPI LPVOID WINAPI MapViewOfFile(HANDLE, DWORD, DWORD, DWORD, SIZE_T);
   197    197   #endif /* SQLITE_OS_WINRT */
   198    198   
   199    199   /*
   200         -** This file mapping API is common to both Win32 and WinRT.
          200  +** These file mapping APIs are common to both Win32 and WinRT.
   201    201   */
          202  +
          203  +WINBASEAPI BOOL WINAPI FlushViewOfFile(LPCVOID, SIZE_T);
   202    204   WINBASEAPI BOOL WINAPI UnmapViewOfFile(LPCVOID);
   203    205   #endif /* SQLITE_WIN32_FILEMAPPING_API */
   204    206   
   205    207   /*
   206    208   ** Some Microsoft compilers lack this definition.
   207    209   */
   208    210   #ifndef INVALID_FILE_ATTRIBUTES
................................................................................
  1079   1081   #else
  1080   1082     { "UuidCreateSequential",     (SYSCALL)0,                      0 },
  1081   1083   #endif
  1082   1084   
  1083   1085   #define osUuidCreateSequential \
  1084   1086           ((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[78].pCurrent)
  1085   1087   
         1088  +#if !defined(SQLITE_NO_SYNC) && SQLITE_MAX_MMAP_SIZE>0
         1089  +  { "FlushViewOfFile",          (SYSCALL)FlushViewOfFile,        0 },
         1090  +#else
         1091  +  { "FlushViewOfFile",          (SYSCALL)0,                      0 },
         1092  +#endif
         1093  +
         1094  +#define osFlushViewOfFile \
         1095  +        ((BOOL(WINAPI*)(LPCVOID,SIZE_T))aSyscall[79].pCurrent)
         1096  +
  1086   1097   }; /* End of the overrideable system calls */
  1087   1098   
  1088   1099   /*
  1089   1100   ** This is the xSetSystemCall() method of sqlite3_vfs for all of the
  1090   1101   ** "win32" VFSes.  Return SQLITE_OK opon successfully updating the
  1091   1102   ** system call pointer, or SQLITE_NOTFOUND if there is no configurable
  1092   1103   ** system call named zName.
................................................................................
  1964   1975   }
  1965   1976   
  1966   1977   /*
  1967   1978   ** Log a I/O error retry episode.
  1968   1979   */
  1969   1980   static void winLogIoerr(int nRetry, int lineno){
  1970   1981     if( nRetry ){
  1971         -    sqlite3_log(SQLITE_IOERR,
         1982  +    sqlite3_log(SQLITE_NOTICE,
  1972   1983         "delayed %dms for lock/sharing conflict at line %d",
  1973   1984         winIoerrRetryDelay*nRetry*(nRetry+1)/2, lineno
  1974   1985       );
  1975   1986     }
  1976   1987   }
  1977   1988   
  1978   1989   #if SQLITE_OS_WINCE
................................................................................
  2784   2795     ** no-op
  2785   2796     */
  2786   2797   #ifdef SQLITE_NO_SYNC
  2787   2798     OSTRACE(("SYNC-NOP pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n",
  2788   2799              osGetCurrentProcessId(), pFile, pFile->h));
  2789   2800     return SQLITE_OK;
  2790   2801   #else
         2802  +#if SQLITE_MAX_MMAP_SIZE>0
         2803  +  if( pFile->pMapRegion ){
         2804  +    if( osFlushViewOfFile(pFile->pMapRegion, 0) ){
         2805  +      OSTRACE(("SYNC-MMAP pid=%lu, pFile=%p, pMapRegion=%p, "
         2806  +               "rc=SQLITE_OK\n", osGetCurrentProcessId(),
         2807  +               pFile, pFile->pMapRegion));
         2808  +    }else{
         2809  +      pFile->lastErrno = osGetLastError();
         2810  +      OSTRACE(("SYNC-MMAP pid=%lu, pFile=%p, pMapRegion=%p, "
         2811  +               "rc=SQLITE_IOERR_MMAP\n", osGetCurrentProcessId(),
         2812  +               pFile, pFile->pMapRegion));
         2813  +      return winLogError(SQLITE_IOERR_MMAP, pFile->lastErrno,
         2814  +                         "winSync1", pFile->zPath);
         2815  +    }
         2816  +  }
         2817  +#endif
  2791   2818     rc = osFlushFileBuffers(pFile->h);
  2792   2819     SimulateIOError( rc=FALSE );
  2793   2820     if( rc ){
  2794   2821       OSTRACE(("SYNC pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n",
  2795   2822                osGetCurrentProcessId(), pFile, pFile->h));
  2796   2823       return SQLITE_OK;
  2797   2824     }else{
  2798   2825       pFile->lastErrno = osGetLastError();
  2799   2826       OSTRACE(("SYNC pid=%lu, pFile=%p, file=%p, rc=SQLITE_IOERR_FSYNC\n",
  2800   2827                osGetCurrentProcessId(), pFile, pFile->h));
  2801   2828       return winLogError(SQLITE_IOERR_FSYNC, pFile->lastErrno,
  2802         -                       "winSync", pFile->zPath);
         2829  +                       "winSync2", pFile->zPath);
  2803   2830     }
  2804   2831   #endif
  2805   2832   }
  2806   2833   
  2807   2834   /*
  2808   2835   ** Determine the current size of a file in bytes
  2809   2836   */
................................................................................
  5578   5605       winGetSystemCall,    /* xGetSystemCall */
  5579   5606       winNextSystemCall,   /* xNextSystemCall */
  5580   5607     };
  5581   5608   #endif
  5582   5609   
  5583   5610     /* Double-check that the aSyscall[] array has been constructed
  5584   5611     ** correctly.  See ticket [bb3a86e890c8e96ab] */
  5585         -  assert( ArraySize(aSyscall)==79 );
         5612  +  assert( ArraySize(aSyscall)==80 );
  5586   5613   
  5587   5614     /* get memory map allocation granularity */
  5588   5615     memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
  5589   5616   #if SQLITE_OS_WINRT
  5590   5617     osGetNativeSystemInfo(&winSysInfo);
  5591   5618   #else
  5592   5619     osGetSystemInfo(&winSysInfo);

Changes to src/vdbe.c.

  1916   1916           applyNumericAffinity(pIn3,0);
  1917   1917         }
  1918   1918       }else if( affinity==SQLITE_AFF_TEXT ){
  1919   1919         if( (pIn1->flags & MEM_Str)==0 && (pIn1->flags & (MEM_Int|MEM_Real))!=0 ){
  1920   1920           testcase( pIn1->flags & MEM_Int );
  1921   1921           testcase( pIn1->flags & MEM_Real );
  1922   1922           sqlite3VdbeMemStringify(pIn1, encoding, 1);
         1923  +        testcase( (flags1&MEM_Dyn) != (pIn1->flags&MEM_Dyn) );
         1924  +        flags1 = (pIn1->flags & ~MEM_TypeMask) | (flags1 & MEM_TypeMask);
  1923   1925         }
  1924   1926         if( (pIn3->flags & MEM_Str)==0 && (pIn3->flags & (MEM_Int|MEM_Real))!=0 ){
  1925   1927           testcase( pIn3->flags & MEM_Int );
  1926   1928           testcase( pIn3->flags & MEM_Real );
  1927   1929           sqlite3VdbeMemStringify(pIn3, encoding, 1);
         1930  +        testcase( (flags3&MEM_Dyn) != (pIn3->flags&MEM_Dyn) );
         1931  +        flags3 = (pIn3->flags & ~MEM_TypeMask) | (flags3 & MEM_TypeMask);
  1928   1932         }
  1929   1933       }
  1930   1934       assert( pOp->p4type==P4_COLLSEQ || pOp->p4.pColl==0 );
  1931   1935       if( pIn1->flags & MEM_Zero ){
  1932   1936         sqlite3VdbeMemExpandBlob(pIn1);
  1933   1937         flags1 &= ~MEM_Zero;
  1934   1938       }
................................................................................
  1957   1961     }else{
  1958   1962       VdbeBranchTaken(res!=0, (pOp->p5 & SQLITE_NULLEQ)?2:3);
  1959   1963       if( res ){
  1960   1964         pc = pOp->p2-1;
  1961   1965       }
  1962   1966     }
  1963   1967     /* Undo any changes made by applyAffinity() to the input registers. */
         1968  +  assert( (pIn1->flags & MEM_Dyn) == (flags1 & MEM_Dyn) );
  1964   1969     pIn1->flags = flags1;
         1970  +  assert( (pIn3->flags & MEM_Dyn) == (flags3 & MEM_Dyn) );
  1965   1971     pIn3->flags = flags3;
  1966   1972     break;
  1967   1973   }
  1968   1974   
  1969   1975   /* Opcode: Permutation * * * P4 *
  1970   1976   **
  1971   1977   ** Set the permutation used by the OP_Compare operator to be the array

Changes to test/attach.test.

   855    855     }
   856    856   } {noname inmem}
   857    857   do_test attach-10.2 {
   858    858     lrange [execsql {
   859    859       PRAGMA database_list;
   860    860     }] 9 end
   861    861   } {4 noname {} 5 inmem {}}
          862  +
          863  +# Attach with a very long URI filename.
          864  +#
          865  +db close
          866  +sqlite3 db test.db -uri 1
          867  +do_execsql_test attach-11.1 {
          868  +  ATTACH printf('file:%09000x/x.db?mode=memory&cache=shared',1) AS aux1;
          869  +  CREATE TABLE aux1.t1(x,y);
          870  +  INSERT INTO aux1.t1(x,y) VALUES(1,2),(3,4);
          871  +  SELECT * FROM aux1.t1;
          872  +} {1 2 3 4}
          873  +
   862    874   
   863    875   finish_test

Changes to test/corruptJ.test.

    70     70   do_test 2.2 {
    71     71     db close
    72     72     hexio_read test.db [expr {9*1024+391}] 8
    73     73   } {00000008814D0401}
    74     74   do_test 2.2b {
    75     75     hexio_write test.db [expr {9*1024+391}] 00000002
    76     76     sqlite3 db test.db
    77         -  catchsql { DROP TABLE t1 }
    78         -} {0 {}}
           77  +  catchsql { PRAGMA secure_delete=ON; DROP TABLE t1; }
           78  +} {1 {database disk image is malformed}}
    79     79   
    80     80   finish_test

Changes to tool/lemon.c.

  1727   1727     char **next,
  1728   1728     int (*cmp)(const char*,const char*)
  1729   1729   ){
  1730   1730     unsigned long offset;
  1731   1731     char *ep;
  1732   1732     char *set[LISTSIZE];
  1733   1733     int i;
  1734         -  offset = (unsigned long)next - (unsigned long)list;
         1734  +  offset = (unsigned long)((char*)next - (char*)list);
  1735   1735     for(i=0; i<LISTSIZE; i++) set[i] = 0;
  1736   1736     while( list ){
  1737   1737       ep = list;
  1738   1738       list = NEXT(list);
  1739   1739       NEXT(ep) = 0;
  1740   1740       for(i=0; i<LISTSIZE-1 && set[i]!=0; i++){
  1741   1741         ep = merge(ep,set[i],cmp,offset);
................................................................................
  1871   1871           break;
  1872   1872         case OPT_DBL:
  1873   1873         case OPT_FDBL:
  1874   1874           dv = strtod(cp,&end);
  1875   1875           if( *end ){
  1876   1876             if( err ){
  1877   1877               fprintf(err,"%sillegal character in floating-point argument.\n",emsg);
  1878         -            errline(i,((unsigned long)end)-(unsigned long)argv[i],err);
         1878  +            errline(i,(int)((char*)end-(char*)argv[i]),err);
  1879   1879             }
  1880   1880             errcnt++;
  1881   1881           }
  1882   1882           break;
  1883   1883         case OPT_INT:
  1884   1884         case OPT_FINT:
  1885   1885           lv = strtol(cp,&end,0);
  1886   1886           if( *end ){
  1887   1887             if( err ){
  1888   1888               fprintf(err,"%sillegal character in integer argument.\n",emsg);
  1889         -            errline(i,((unsigned long)end)-(unsigned long)argv[i],err);
         1889  +            errline(i,(int)((char*)end-(char*)argv[i]),err);
  1890   1890             }
  1891   1891             errcnt++;
  1892   1892           }
  1893   1893           break;
  1894   1894         case OPT_STR:
  1895   1895         case OPT_FSTR:
  1896   1896           sv = cp;