/ Check-in [e072cb3e]
Login

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

Overview
Comment:Fix a problem with "DEFAULT (-(-9223372036854775808))" clauses in ALTER TABLE ... ADD COLUMN commands.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: e072cb3ee2a03d786c08230cecc6e970de2cec5b
User & Date: dan 2014-03-04 21:00:20
Context
2014-03-04
21:19
Avoid indexing off the front end of an array when creating a view with two or more blank column names in the SELECT statement that defines the view. check-in: 554501f1 user: drh tags: trunk
21:00
Fix a problem with "DEFAULT (-(-9223372036854775808))" clauses in ALTER TABLE ... ADD COLUMN commands. check-in: e072cb3e user: dan tags: trunk
18:06
Fix a potential memory use-after-free problem following an OOM error. check-in: 767ccb1f user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/vdbemem.c.

  1038   1038     }else if( op==TK_UMINUS ) {
  1039   1039       /* This branch happens for multiple negative signs.  Ex: -(-5) */
  1040   1040       if( SQLITE_OK==sqlite3ValueFromExpr(db,pExpr->pLeft,enc,affinity,&pVal) 
  1041   1041        && pVal!=0
  1042   1042       ){
  1043   1043         sqlite3VdbeMemNumerify(pVal);
  1044   1044         if( pVal->u.i==SMALLEST_INT64 ){
  1045         -        pVal->flags &= MEM_Int;
         1045  +        pVal->flags &= ~MEM_Int;
  1046   1046           pVal->flags |= MEM_Real;
  1047         -        pVal->r = (double)LARGEST_INT64;
         1047  +        pVal->r = (double)SMALLEST_INT64;
  1048   1048         }else{
  1049   1049           pVal->u.i = -pVal->u.i;
  1050   1050         }
  1051   1051         pVal->r = -pVal->r;
  1052   1052         sqlite3ValueApplyAffinity(pVal, affinity, enc);
  1053   1053       }
  1054   1054     }else if( op==TK_NULL ){

Changes to test/alter4.test.

   330    330   } {}
   331    331   do_test alter4-8.2 {
   332    332     execsql {
   333    333       SELECT sql FROM sqlite_temp_master WHERE name = 't4';
   334    334     }
   335    335   } [list $::sql]
   336    336   
          337  +
          338  +# Test that a default value equal to -1 multipied by the smallest possible
          339  +# 64-bit integer is correctly converted to a real.
          340  +do_execsql_test alter4-9.1 {
          341  +  CREATE TABLE t5(
          342  +    a INTEGER DEFAULT -9223372036854775808,
          343  +    b INTEGER DEFAULT (-(-9223372036854775808))
          344  +  );
          345  +  INSERT INTO t5 DEFAULT VALUES;
          346  +}
          347  +
          348  +do_execsql_test alter4-9.2 { SELECT typeof(a), a, typeof(b), b FROM t5; } {
          349  +  integer -9223372036854775808
          350  +  real     9.22337203685478e+18
          351  +}
          352  +
          353  +do_execsql_test alter4-9.3 { 
          354  +  ALTER TABLE t5 ADD COLUMN c INTEGER DEFAULT (-(-9223372036854775808));
          355  +  SELECT typeof(c), c FROM t5;
          356  +} {real 9.22337203685478e+18}
          357  +
   337    358   finish_test