/ Check-in [0715ce16]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Avoid left-shifts of signed integers.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 0715ce164333e27671efbec8796f238df98cc287
User & Date: drh 2016-05-03 00:04:55
Context
2016-05-03
14:57
The session extension is disabled by default. To enable it using --enable-session on ./configure on unix and add SESSION=1 to the nmake on Windows. Or add -DSQLITE_ENABLE_SESSION and -DSQLITE_ENABLE_PREUPDATE_HOOK to build manually. check-in: bcaa650e user: drh tags: trunk
13:14
Turn the session extension off by default. Enable using --enable-session on configure scripts, or using the SESSION=1 argument to nmake on Windows. Closed-Leaf check-in: e462cde2 user: drh tags: session-make
00:04
Avoid left-shifts of signed integers. check-in: 0715ce16 user: drh tags: trunk
2016-05-02
19:05
Remove some randomness from test script temptable2.test. check-in: 5830cf72 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/session/sqlite3session.c.

   274    274   ** Read a varint value from aBuf[] into *piVal. Return the number of 
   275    275   ** bytes read.
   276    276   */
   277    277   static int sessionVarintGet(u8 *aBuf, int *piVal){
   278    278     return getVarint32(aBuf, *piVal);
   279    279   }
   280    280   
          281  +/* Load an unaligned and unsigned 32-bit integer */
          282  +#define SESSION_UINT32(x) (((u32)(x)[0]<<24)|((x)[1]<<16)|((x)[2]<<8)|(x)[3])
          283  +
   281    284   /*
   282    285   ** Read a 64-bit big-endian integer value from buffer aRec[]. Return
   283    286   ** the value read.
   284    287   */
   285    288   static sqlite3_int64 sessionGetI64(u8 *aRec){
   286         -  return (((sqlite3_int64)aRec[0]) << 56)
   287         -       + (((sqlite3_int64)aRec[1]) << 48)
   288         -       + (((sqlite3_int64)aRec[2]) << 40)
   289         -       + (((sqlite3_int64)aRec[3]) << 32)
   290         -       + (((sqlite3_int64)aRec[4]) << 24)
   291         -       + (((sqlite3_int64)aRec[5]) << 16)
   292         -       + (((sqlite3_int64)aRec[6]) <<  8)
   293         -       + (((sqlite3_int64)aRec[7]) <<  0);
          289  +  u64 x = SESSION_UINT32(aRec);
          290  +  u32 y = SESSION_UINT32(aRec+4);
          291  +  x = (x<<32) + y;
          292  +  return (sqlite3_int64)x;
   294    293   }
   295    294   
   296    295   /*
   297    296   ** Write a 64-bit big-endian integer value to the buffer aBuf[].
   298    297   */
   299    298   static void sessionPutI64(u8 *aBuf, sqlite3_int64 i){
   300    299     aBuf[0] = (i>>56) & 0xFF;

Changes to src/test1.c.

  6696   6696     int objc,
  6697   6697     Tcl_Obj *CONST objv[]
  6698   6698   ){
  6699   6699     const char *zSql1;
  6700   6700     const char *zSql2;
  6701   6701     int nStep; 
  6702   6702     int iStep; 
  6703         -  int iCksum1 = 0; 
  6704         -  int iCksum2 = 0; 
         6703  +  unsigned int iCksum1 = 0; 
         6704  +  unsigned int iCksum2 = 0; 
  6705   6705     int rc;
  6706   6706     int iB;
  6707   6707     sqlite3 *db;
  6708   6708     sqlite3_stmt *pStmt;
  6709   6709     
  6710   6710     if( objc!=5 ){
  6711   6711       Tcl_WrongNumArgs(interp, 1, objv, "DB SQL1 NSTEP SQL2");
................................................................................
  6724   6724     for(iStep=0; iStep<nStep && SQLITE_ROW==sqlite3_step(pStmt); iStep++){
  6725   6725       int a = sqlite3_column_int(pStmt, 0);
  6726   6726       if( a!=sqlite3_column_int(pStmt, iB) ){
  6727   6727         Tcl_AppendResult(interp, "data error: (a!=b)", 0);
  6728   6728         return TCL_ERROR;
  6729   6729       }
  6730   6730   
  6731         -    iCksum1 += (iCksum1 << 3) + a;
         6731  +    iCksum1 += (iCksum1 << 3) + (unsigned int)a;
  6732   6732     }
  6733   6733     rc = sqlite3_finalize(pStmt);
  6734   6734     if( rc!=SQLITE_OK ) goto sql_error;
  6735   6735   
  6736   6736     rc = sqlite3_prepare_v2(db, zSql2, -1, &pStmt, 0);
  6737   6737     if( rc!=SQLITE_OK ) goto sql_error;
  6738   6738     for(iStep=0; SQLITE_ROW==sqlite3_step(pStmt); iStep++){
  6739   6739       int a = sqlite3_column_int(pStmt, 0);
  6740         -    iCksum2 += (iCksum2 << 3) + a;
         6740  +    iCksum2 += (iCksum2 << 3) + (unsigned int)a;
  6741   6741     }
  6742   6742     rc = sqlite3_finalize(pStmt);
  6743   6743     if( rc!=SQLITE_OK ) goto sql_error;
  6744   6744   
  6745   6745     if( iCksum1!=iCksum2 ){
  6746   6746       Tcl_AppendResult(interp, "checksum mismatch", 0);
  6747   6747       return TCL_ERROR;