/ Check-in [69f996e0]
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:Correctly set the length of the string in bytes when transforming an OP_String8 to OP_String in a utf-16 vdbe program. (CVS 2949)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 69f996e0fac1dc50b8c43d5fa132f79776843819
User & Date: danielk1977 2006-01-15 14:11:49
Context
2006-01-15
17:27
Clean up comments in os_unix.c. (CVS 2950) check-in: 2170e803 user: drh tags: trunk
14:11
Correctly set the length of the string in bytes when transforming an OP_String8 to OP_String in a utf-16 vdbe program. (CVS 2949) check-in: 69f996e0 user: danielk1977 tags: trunk
13:13
Fix a buffer-overrun that could occur after a malloc() failure. (CVS 2948) check-in: 66252221 user: danielk1977 tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/vdbe.c.

    39     39   **
    40     40   ** Various scripts scan this source file in order to generate HTML
    41     41   ** documentation, headers files, or other derived files.  The formatting
    42     42   ** of the code in this file is, therefore, important.  See other comments
    43     43   ** in this file for details.  If in doubt, do not deviate from existing
    44     44   ** commenting and indentation practices when changing or adding code.
    45     45   **
    46         -** $Id: vdbe.c,v 1.529 2006/01/13 17:12:01 danielk1977 Exp $
           46  +** $Id: vdbe.c,v 1.530 2006/01/15 14:11:49 danielk1977 Exp $
    47     47   */
    48     48   #include "sqliteInt.h"
    49     49   #include "os.h"
    50     50   #include <ctype.h>
    51     51   #include "vdbeInt.h"
    52     52   
    53     53   /*
................................................................................
   661    661     pTos->flags |= MEM_Real;
   662    662     sqlite3VdbeChangeEncoding(pTos, encoding);
   663    663     break;
   664    664   }
   665    665   
   666    666   /* Opcode: String8 * * P3
   667    667   **
   668         -** P3 points to a nul terminated UTF-8 string that is P1 character long
   669         -** (not counting the nul terminator). This opcode is transformed
          668  +** P3 points to a nul terminated UTF-8 string. This opcode is transformed 
   670    669   ** into an OP_String before it is executed for the first time.
   671    670   */
   672    671   case OP_String8: {         /* same as TK_STRING */
   673    672     assert( pOp->p3!=0 );
   674    673     pOp->opcode = OP_String;
   675    674     pOp->p1 = strlen(pOp->p3);
   676    675   
................................................................................
   683    682       pTos->flags &= ~(MEM_Dyn);
   684    683       pTos->flags |= MEM_Static;
   685    684       if( pOp->p3type==P3_DYNAMIC ){
   686    685         sqliteFree(pOp->p3);
   687    686       }
   688    687       pOp->p3type = P3_DYNAMIC;
   689    688       pOp->p3 = pTos->z;
   690         -    pOp->p1 *= 2;
          689  +    pOp->p1 = pTos->n;
   691    690       break;
   692    691     }
   693    692   #endif
   694    693     /* Otherwise fall through to the next case, OP_String */
   695    694   }
   696    695     
   697    696   /* Opcode: String P1 * P3
   698    697   **
   699         -** The string value P3 of length P1 is pushed onto the stack.
          698  +** The string value P3 of length P1 (bytes) is pushed onto the stack.
   700    699   */
   701    700   case OP_String: {
   702    701     pTos++;
   703    702     assert( pOp->p3!=0 );
   704    703     pTos->flags = MEM_Str|MEM_Static|MEM_Term;
   705    704     pTos->z = pOp->p3;
   706    705     pTos->n = pOp->p1;

Changes to test/alter.test.

     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #*************************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this script is testing the ALTER TABLE statement.
    13     13   #
    14         -# $Id: alter.test,v 1.14 2006/01/14 08:02:28 danielk1977 Exp $
           14  +# $Id: alter.test,v 1.15 2006/01/15 14:11:49 danielk1977 Exp $
    15     15   #
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   
    20     20   # If SQLITE_OMIT_ALTERTABLE is defined, omit this file.
    21     21   ifcapable !altertable {
................................................................................
   547    547       ALTER TABLE tbl1 RENAME TO tbl2;
   548    548       SELECT * FROM tbl2;
   549    549     } db2
   550    550   } {x y z}
   551    551   do_test alter-5.3 {
   552    552     db2 close
   553    553   } {}
          554  +
          555  +foreach tblname [execsql {
          556  +  SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite%'
          557  +}] {
          558  +  execsql "DROP TABLE \"$tblname\""
          559  +}
   554    560   
   555    561   set ::tbl_name "abc\uABCDdef"
   556         -do_test alter-5.1 {
          562  +do_test alter-6.1 {
   557    563     string length $::tbl_name
   558    564   } {7}
   559         -do_test alter-5.2 {
          565  +do_test alter-6.2 {
   560    566     execsql "
   561    567       CREATE TABLE ${tbl_name}(a, b, c);
   562    568     "
   563    569     set ::oid [execsql {SELECT max(oid) FROM sqlite_master}]
   564    570     execsql {
   565    571       SELECT sql FROM sqlite_master WHERE oid = $::oid;
   566    572     }
   567    573   } "{CREATE TABLE ${::tbl_name}(a, b, c)}"
          574  +execsql "
          575  +  SELECT * FROM ${::tbl_name}
          576  +"
   568    577   set ::tbl_name2 "abcXdef"
   569         -do_test alter-5.2 {
          578  +do_test alter-6.3 {
   570    579     execsql "
   571    580       ALTER TABLE $::tbl_name RENAME TO $::tbl_name2 
   572    581     "
   573    582     execsql {
   574    583       SELECT sql FROM sqlite_master WHERE oid = $::oid;
   575    584     }
   576    585   } "{CREATE TABLE '${::tbl_name2}'(a, b, c)}"
   577         -do_test alter-5.3 {
          586  +do_test alter-6.4 {
   578    587     execsql "
   579    588       ALTER TABLE $::tbl_name2 RENAME TO $::tbl_name
   580    589     "
   581    590     execsql {
   582    591       SELECT sql FROM sqlite_master WHERE oid = $::oid;
   583    592     }
   584    593   } "{CREATE TABLE '${::tbl_name}'(a, b, c)}"
   585    594   set ::col_name ghi\1234\jkl
   586         -do_test alter-5.4 {
          595  +do_test alter-6.5 {
   587    596     execsql "
   588    597       ALTER TABLE $::tbl_name ADD COLUMN $::col_name VARCHAR
   589    598     "
   590    599     execsql {
   591    600       SELECT sql FROM sqlite_master WHERE oid = $::oid;
   592    601     }
   593    602   } "{CREATE TABLE '${::tbl_name}'(a, b, c, $::col_name VARCHAR)}"
   594    603   set ::col_name2 B\3421\A
   595         -do_test alter-5.5 {
          604  +do_test alter-6.6 {
   596    605     db close
   597    606     sqlite3 db test.db
   598    607     execsql "
   599    608       ALTER TABLE $::tbl_name ADD COLUMN $::col_name2
   600    609     "
   601    610     execsql {
   602    611       SELECT sql FROM sqlite_master WHERE oid = $::oid;
   603    612     }
   604    613   } "{CREATE TABLE '${::tbl_name}'(a, b, c, $::col_name VARCHAR, $::col_name2)}"
   605         -do_test alter-5.6 {
          614  +do_test alter-6.7 {
   606    615     execsql "
   607    616       INSERT INTO ${::tbl_name} VALUES(1, 2, 3, 4, 5);
   608    617       SELECT $::col_name, $::col_name2 FROM $::tbl_name;
   609    618     "
   610    619   } {4 5}
   611    620   
   612    621   finish_test
   613    622