SQLite
Check-in [ff67d87894]
Not logged in
Overview
SHA1 Hash:ff67d87894eeb0036374235c5723e267536909f9
Date: 2013-03-01 15:02:52
User: drh
Comment:Fix the handling of UTF16 surrogate pairs in the char() function.
Tags And Properties
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);