Fix an instance of signed arithmetic overflow and an one bit-shift overflow.
Mark six other signed arithmetic overflow locations that need fixing.

FossilOrigin-Name: 04abab71ecd52f6070b9f84781a3df3d6dba7722
diff --git a/src/expr.c b/src/expr.c
index b7b7394..57243c7 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -1964,7 +1964,7 @@
     c = sqlite3Atoi64(z, &value, sqlite3Strlen30(z), SQLITE_UTF8);
     if( c==0 || (c==2 && negFlag) ){
       char *zV;
-      if( negFlag ){ value = -value; }
+      if( negFlag ){ value = -value; } /* CLANG */
       zV = dup8bytes(v, (char*)&value);
       sqlite3VdbeAddOp4(v, OP_Int64, 0, iMem, 0, zV, P4_INT64);
     }else{
diff --git a/src/func.c b/src/func.c
index 19c6d22..2f21ac0 100644
--- a/src/func.c
+++ b/src/func.c
@@ -1240,7 +1240,7 @@
       i64 v = sqlite3_value_int64(argv[0]);
       p->rSum += v;
       if( (p->approx|p->overflow)==0 ){
-        i64 iNewSum = p->iSum + v;
+        i64 iNewSum = p->iSum + v;    /* CLANG */
         int s1 = (int)(p->iSum >> (sizeof(i64)*8-1));
         int s2 = (int)(v       >> (sizeof(i64)*8-1));
         int s3 = (int)(iNewSum >> (sizeof(i64)*8-1));
diff --git a/src/printf.c b/src/printf.c
index c88bb30..21b6c0e 100644
--- a/src/printf.c
+++ b/src/printf.c
@@ -400,7 +400,7 @@
             v = va_arg(ap,int);
           }
           if( v<0 ){
-            longvalue = -v;
+            longvalue = -v;  /* CLANG */
             prefix = '-';
           }else{
             longvalue = v;
diff --git a/src/update.c b/src/update.c
index 8bf58d7..045b4d1 100644
--- a/src/update.c
+++ b/src/update.c
@@ -396,7 +396,7 @@
         pTrigger, pChanges, 0, TRIGGER_BEFORE|TRIGGER_AFTER, pTab, onError
     );
     for(i=0; i<pTab->nCol; i++){
-      if( aXRef[i]<0 || oldmask==0xffffffff || (oldmask & (1<<i)) ){
+      if( aXRef[i]<0 || oldmask==0xffffffff || (i<32 && (oldmask & (1<<i))) ){
         sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, i, regOld+i);
       }else{
         sqlite3VdbeAddOp2(v, OP_Null, 0, regOld+i);
diff --git a/src/util.c b/src/util.c
index dfa127b..ca22749 100644
--- a/src/util.c
+++ b/src/util.c
@@ -475,9 +475,9 @@
   zStart = zNum;
   while( zNum<zEnd && zNum[0]=='0' ){ zNum+=incr; } /* Skip leading zeros. */
   for(i=0; &zNum[i]<zEnd && (c=zNum[i])>='0' && c<='9'; i+=incr){
-    v = v*10 + c - '0';
+    v = v*10 + c - '0';  /* CLANG */
   }
-  *pNum = neg ? -v : v;
+  *pNum = neg ? -v : v;  /* CLANG */
   testcase( i==18 );
   testcase( i==19 );
   testcase( i==20 );
diff --git a/src/vdbe.c b/src/vdbe.c
index 00ed143..3a73976 100644
--- a/src/vdbe.c
+++ b/src/vdbe.c
@@ -1246,7 +1246,7 @@
     iA = pIn1->u.i;
     iB = pIn2->u.i;
     switch( pOp->opcode ){
-      case OP_Add:         iB += iA;       break;
+      case OP_Add:         iB += iA;       break;   /* CLANG */
       case OP_Subtract:    iB -= iA;       break;
       case OP_Multiply:    iB *= iA;       break;
       case OP_Divide: {
diff --git a/src/vdbeaux.c b/src/vdbeaux.c
index 64ff489..4a1b1ef 100644
--- a/src/vdbeaux.c
+++ b/src/vdbeaux.c
@@ -2497,7 +2497,13 @@
     if( file_format>=4 && (i&1)==i ){
       return 8+(u32)i;
     }
-    u = i<0 ? -i : i;
+    if( i<0 ){
+      if( i<(-MAX_6BYTE) ) return 6;
+      /* Previous test prevents:  u = -(-9223372036854775808) */
+      u = -i;
+    }else{
+      u = i;
+    }
     if( u<=127 ) return 1;
     if( u<=32767 ) return 2;
     if( u<=8388607 ) return 3;