aboutsummaryrefslogtreecommitdiff
path: root/src/expr.c
diff options
context:
space:
mode:
authordrh <>2023-10-22 23:44:32 +0000
committerdrh <>2023-10-22 23:44:32 +0000
commit5e6dde3b3556672b6272456608578ff7b585c62a (patch)
tree41d4736c1c987e00c09d870fe4d4654babe0a22e /src/expr.c
parenta63539143da79df705746156923a6bfd8248932f (diff)
downloadsqlite-5e6dde3b3556672b6272456608578ff7b585c62a.tar.gz
sqlite-5e6dde3b3556672b6272456608578ff7b585c62a.zip
Fix [f5c01676fd281e93] so that it always preserves 8-byte alignment for Expr
objects. Add new assert() statement to verify this. FossilOrigin-Name: 678a9728dc6b88d8ef924c86603056df18204bc9a9c4776b9baffd7c5b10c5f2
Diffstat (limited to 'src/expr.c')
-rw-r--r--src/expr.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/expr.c b/src/expr.c
index 73ff55373..3eb2c03ac 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -1544,6 +1544,7 @@ static int dupedExprSize(const Expr *p){
nByte = dupedExprNodeSize(p, EXPRDUP_REDUCE);
if( p->pLeft ) nByte += dupedExprSize(p->pLeft);
if( p->pRight ) nByte += dupedExprSize(p->pRight);
+ assert( nByte==ROUND8(nByte) );
return nByte;
}
@@ -1600,11 +1601,12 @@ static Expr *exprDup(
nAlloc = dupedExprSize(p);
}else if( !ExprHasProperty(p, EP_IntValue) && p->u.zToken ){
nToken = sqlite3Strlen30NN(p->u.zToken)+1;
- nAlloc = EXPR_FULLSIZE + nToken;
+ nAlloc = EXPR_FULLSIZE + ROUND8(nToken);
}else{
nToken = 0;
nAlloc = EXPR_FULLSIZE;
}
+ assert( nAlloc==ROUND8(nAlloc) );
sEdupBuf.zAlloc = sqlite3DbMallocRawNN(db, nAlloc);
#ifdef SQLITE_DEBUG
sEdupBuf.zEnd = sEdupBuf.zAlloc ? sEdupBuf.zAlloc+nAlloc : 0;
@@ -1613,6 +1615,7 @@ static Expr *exprDup(
staticFlag = 0;
}
pNew = (Expr *)sEdupBuf.zAlloc;
+ assert( EIGHT_BYTE_ALIGNMENT(pNew) );
if( pNew ){
/* Set nNewSize to the size allocated for the structure pointed to
@@ -1621,7 +1624,7 @@ static Expr *exprDup(
** by the copy of the p->u.zToken string (if any).
*/
const unsigned nStructSize = dupedExprStructSize(p, dupFlags);
- const int nNewSize = nStructSize & 0xfff;
+ int nNewSize = nStructSize & 0xfff;
if( nToken<0 ){
if( !ExprHasProperty(p, EP_IntValue) && p->u.zToken ){
nToken = sqlite3Strlen30(p->u.zToken) + 1;
@@ -1633,7 +1636,6 @@ static Expr *exprDup(
assert( (int)(sEdupBuf.zEnd - sEdupBuf.zAlloc) >= nNewSize+nToken );
assert( ExprHasProperty(p, EP_Reduced)==0 );
memcpy(sEdupBuf.zAlloc, p, nNewSize);
- sEdupBuf.zAlloc += nNewSize;
}else{
u32 nSize = (u32)exprStructSize(p);
assert( (int)(sEdupBuf.zEnd - sEdupBuf.zAlloc) >= EXPR_FULLSIZE+nToken );
@@ -1641,7 +1643,7 @@ static Expr *exprDup(
if( nSize<EXPR_FULLSIZE ){
memset(&sEdupBuf.zAlloc[nSize], 0, EXPR_FULLSIZE-nSize);
}
- sEdupBuf.zAlloc += EXPR_FULLSIZE;
+ nNewSize = EXPR_FULLSIZE;
}
/* Set the EP_Reduced, EP_TokenOnly, and EP_Static flags appropriately. */
@@ -1656,10 +1658,11 @@ static Expr *exprDup(
/* Copy the p->u.zToken string, if any. */
assert( nToken>=0 );
if( nToken>0 ){
- char *zToken = pNew->u.zToken = (char*)sEdupBuf.zAlloc;
+ char *zToken = pNew->u.zToken = (char*)&sEdupBuf.zAlloc[nNewSize];
memcpy(zToken, p->u.zToken, nToken);
- sEdupBuf.zAlloc += nToken;
+ nNewSize += nToken;
}
+ sEdupBuf.zAlloc += ROUND8(nNewSize);
if( ((p->flags|pNew->flags)&(EP_TokenOnly|EP_Leaf))==0 ){