diff options
author | drh <drh@noemail.net> | 2011-03-08 02:38:28 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2011-03-08 02:38:28 +0000 |
commit | d50ffc416fc47ad9ed6c643d4aaba0df2e59254c (patch) | |
tree | 56d21715dc2604ca11fe995a74ee5e187622cb23 /src/expr.c | |
parent | 2327275b8c3c34b4ffb4be1fd81bbcf5b180c32c (diff) | |
download | sqlite-d50ffc416fc47ad9ed6c643d4aaba0df2e59254c.tar.gz sqlite-d50ffc416fc47ad9ed6c643d4aaba0df2e59254c.zip |
Fix additional cases of possible signed integer overflow, especially with
regard to negation.
FossilOrigin-Name: 2d5800bd8cfc7d7f5578a71b1aeaa74b2ec4b372
Diffstat (limited to 'src/expr.c')
-rw-r--r-- | src/expr.c | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/src/expr.c b/src/expr.c index b938d9657..f80ae2ba2 100644 --- a/src/expr.c +++ b/src/expr.c @@ -389,6 +389,7 @@ Expr *sqlite3ExprAlloc( if( op!=TK_INTEGER || pToken->z==0 || sqlite3GetInt32(pToken->z, &iValue)==0 ){ nExtra = pToken->n+1; + assert( iValue>=0 ); } } pNew = sqlite3DbMallocZero(db, sizeof(Expr)+nExtra); @@ -614,6 +615,8 @@ void sqlite3ExprAssignVarNumber(Parse *pParse, Expr *pExpr){ */ void sqlite3ExprDelete(sqlite3 *db, Expr *p){ if( p==0 ) return; + /* Sanity check: Assert that the IntValue is non-negative if it exists */ + assert( !ExprHasProperty(p, EP_IntValue) || p->u.iValue>=0 ); if( !ExprHasAnyProperty(p, EP_TokenOnly) ){ sqlite3ExprDelete(db, p->pLeft); sqlite3ExprDelete(db, p->pRight); @@ -1223,13 +1226,6 @@ int sqlite3ExprIsInteger(Expr *p, int *pValue){ } default: break; } - if( rc ){ - assert( ExprHasAnyProperty(p, EP_Reduced|EP_TokenOnly) - || (p->flags2 & EP2_MallocedToken)==0 ); - p->op = TK_INTEGER; - p->flags |= EP_IntValue; - p->u.iValue = *pValue; - } return rc; } @@ -1954,6 +1950,7 @@ static void codeInteger(Parse *pParse, Expr *pExpr, int negFlag, int iMem){ Vdbe *v = pParse->pVdbe; if( pExpr->flags & EP_IntValue ){ int i = pExpr->u.iValue; + assert( i>=0 ); if( negFlag ) i = -i; sqlite3VdbeAddOp2(v, OP_Integer, i, iMem); }else{ |