SQLite

Check-in [e072cb3ee2]
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
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: e072cb3ee2a03d786c08230cecc6e970de2cec5b
User & Date: dan 2014-03-04 21:00:20.840
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: 554501f158 user: drh tags: trunk)
21:00
Fix a problem with "DEFAULT (-(-9223372036854775808))" clauses in ALTER TABLE ... ADD COLUMN commands. (check-in: e072cb3ee2 user: dan tags: trunk)
18:06
Fix a potential memory use-after-free problem following an OOM error. (check-in: 767ccb1fa1 user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/vdbemem.c.
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
  }else if( op==TK_UMINUS ) {
    /* This branch happens for multiple negative signs.  Ex: -(-5) */
    if( SQLITE_OK==sqlite3ValueFromExpr(db,pExpr->pLeft,enc,affinity,&pVal) 
     && pVal!=0
    ){
      sqlite3VdbeMemNumerify(pVal);
      if( pVal->u.i==SMALLEST_INT64 ){
        pVal->flags &= MEM_Int;
        pVal->flags |= MEM_Real;
        pVal->r = (double)LARGEST_INT64;
      }else{
        pVal->u.i = -pVal->u.i;
      }
      pVal->r = -pVal->r;
      sqlite3ValueApplyAffinity(pVal, affinity, enc);
    }
  }else if( op==TK_NULL ){







|

|







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





















337
} {}
do_test alter4-8.2 {
  execsql {
    SELECT sql FROM sqlite_temp_master WHERE name = 't4';
  }
} [list $::sql]






















finish_test







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
} {}
do_test alter4-8.2 {
  execsql {
    SELECT sql FROM sqlite_temp_master WHERE name = 't4';
  }
} [list $::sql]


# Test that a default value equal to -1 multipied by the smallest possible
# 64-bit integer is correctly converted to a real.
do_execsql_test alter4-9.1 {
  CREATE TABLE t5(
    a INTEGER DEFAULT -9223372036854775808,
    b INTEGER DEFAULT (-(-9223372036854775808))
  );
  INSERT INTO t5 DEFAULT VALUES;
}

do_execsql_test alter4-9.2 { SELECT typeof(a), a, typeof(b), b FROM t5; } {
  integer -9223372036854775808
  real     9.22337203685478e+18
}

do_execsql_test alter4-9.3 { 
  ALTER TABLE t5 ADD COLUMN c INTEGER DEFAULT (-(-9223372036854775808));
  SELECT typeof(c), c FROM t5;
} {real 9.22337203685478e+18}

finish_test