/ Check-in [4fa831d5]
Login

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

Overview
Comment:Improved error handling for the ".open --hexdb" command of the CLI.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 4fa831d5cd5861f6a0a8f08a738b2d4d371fb2a788178ce86482c5bba761f9de
User & Date: drh 2019-05-09 11:18:41
Context
2019-05-09
11:21
Merge accidental fork in trunk. check-in: ec937303 user: dan tags: trunk
11:18
Improved error handling for the ".open --hexdb" command of the CLI. check-in: 4fa831d5 user: drh tags: trunk
2019-05-08
23:55
Ensure that the sqlite3BtreeLast() interface initializes the *pRes return to zero if the cursor is already sitting on the last entry of the table. Manuel Rigger found the obscure test case for which this makes a difference. check-in: ebe4845c user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/shell.c.in.

  3880   3880       if( in==0 ) in = stdin;
  3881   3881     }
  3882   3882     *pnData = 0;
  3883   3883     nLine++;
  3884   3884     if( fgets(zLine, sizeof(zLine), in)==0 ) goto readHexDb_error;
  3885   3885     rc = sscanf(zLine, "| size %d pagesize %d", &n, &pgsz);
  3886   3886     if( rc!=2 ) goto readHexDb_error;
  3887         -  if( n<=0 ) goto readHexDb_error;
  3888         -  a = sqlite3_malloc( n );
         3887  +  if( n<0 ) goto readHexDb_error;
         3888  +  a = sqlite3_malloc( n ? n : 1 );
  3889   3889     if( a==0 ){
  3890   3890       utf8_printf(stderr, "Out of memory!\n");
  3891   3891       goto readHexDb_error;
  3892   3892     }
  3893   3893     memset(a, 0, n);
  3894   3894     if( pgsz<512 || pgsz>65536 || (pgsz & (pgsz-1))!=0 ){
  3895   3895       utf8_printf(stderr, "invalid pagesize\n");
................................................................................
  3920   3920       fclose(in);
  3921   3921     }else{
  3922   3922       p->lineno = nLine;
  3923   3923     }
  3924   3924     return a;
  3925   3925   
  3926   3926   readHexDb_error:
  3927         -  if( in!=stdin ){
         3927  +  if( in!=p->in ){
  3928   3928       fclose(in);
  3929   3929     }else{
  3930   3930       while( fgets(zLine, sizeof(zLine), p->in)!=0 ){
  3931   3931         nLine++;
  3932   3932         if(strncmp(zLine, "| end ", 6)==0 ) break;
  3933   3933       }
  3934   3934       p->lineno = nLine;
................................................................................
  4162   4162         int nData = 0;
  4163   4163         unsigned char *aData;
  4164   4164         if( p->openMode==SHELL_OPEN_DESERIALIZE ){
  4165   4165           aData = (unsigned char*)readFile(p->zDbFilename, &nData);
  4166   4166         }else{
  4167   4167           aData = readHexDb(p, &nData);
  4168   4168           if( aData==0 ){
  4169         -          utf8_printf(stderr, "Error in hexdb input\n");
  4170   4169             return;
  4171   4170           }
  4172   4171         }
  4173   4172         rc = sqlite3_deserialize(p->db, "main", aData, nData, nData,
  4174   4173                      SQLITE_DESERIALIZE_RESIZEABLE |
  4175   4174                      SQLITE_DESERIALIZE_FREEONCLOSE);
  4176   4175         if( rc ){