SQLite

Check-in [ff67d878]
Login
Overview
Comment:Fix the handling of UTF16 surrogate pairs in the char() function.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:ff67d87894eeb0036374235c5723e267536909f9
User & Date: drh 2013-03-01 15:02:52
Context
2013-03-01
21:01
Fix an overly restrictive assert() in the pager. check-in: f476eace user: drh tags: trunk
15:02
Fix the handling of UTF16 surrogate pairs in the char() function. check-in: ff67d878 user: drh tags: trunk
01:07
Always use strncmp() rather than memcmp() when comparing strings where one or other string might be less than the length parameter, since optimized versions of memcmp() might read past the first difference and in so doing generate an access violation. check-in: d7343558 user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/func.c.

995
996
997
998
999
1000
1001

1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
  for(i=0; i<argc; i++){
    sqlite3_int64 x;
    unsigned c;
    x = sqlite3_value_int64(argv[i]);
    if( x<0 || x>0x10ffff ) x = 0xfffd;
    c = (unsigned)(x & 0x1fffff);
    if( c<=0xFFFF ){

      *zOut++ = (u8)(c&0x00FF);
      *zOut++ = (u8)((c>>8)&0x00FF);
    }else{
      if( c>=0xd800 && c<=0xdbff ) c = 0xfffd;
      *zOut++ = (u8)(((c>>10)&0x003F) + (((c-0x10000)>>10)&0x00C0));
      *zOut++ = (u8)(0x00D8 + (((c-0x10000)>>18)&0x03));
      *zOut++ = (u8)(c&0x00FF);
      *zOut++ = (u8)(0x00DC + ((c>>8)&0x03));
    }
  }
  sqlite3_result_text16le(context, (char*)z, (int)(zOut-z), sqlite3_free);







>



<







995
996
997
998
999
1000
1001
1002
1003
1004
1005

1006
1007
1008
1009
1010
1011
1012
  for(i=0; i<argc; i++){
    sqlite3_int64 x;
    unsigned c;
    x = sqlite3_value_int64(argv[i]);
    if( x<0 || x>0x10ffff ) x = 0xfffd;
    c = (unsigned)(x & 0x1fffff);
    if( c<=0xFFFF ){
      if( c>=0xd800 && c<=0xdfff ) c = 0xfffd;
      *zOut++ = (u8)(c&0x00FF);
      *zOut++ = (u8)((c>>8)&0x00FF);
    }else{

      *zOut++ = (u8)(((c>>10)&0x003F) + (((c-0x10000)>>10)&0x00C0));
      *zOut++ = (u8)(0x00D8 + (((c-0x10000)>>18)&0x03));
      *zOut++ = (u8)(c&0x00FF);
      *zOut++ = (u8)(0x00DC + ((c>>8)&0x03));
    }
  }
  sqlite3_result_text16le(context, (char*)z, (int)(zOut-z), sqlite3_free);