/ Check-in [ff67d878]
Login

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

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 Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/func.c.

   995    995     for(i=0; i<argc; i++){
   996    996       sqlite3_int64 x;
   997    997       unsigned c;
   998    998       x = sqlite3_value_int64(argv[i]);
   999    999       if( x<0 || x>0x10ffff ) x = 0xfffd;
  1000   1000       c = (unsigned)(x & 0x1fffff);
  1001   1001       if( c<=0xFFFF ){
         1002  +      if( c>=0xd800 && c<=0xdfff ) c = 0xfffd;
  1002   1003         *zOut++ = (u8)(c&0x00FF);
  1003   1004         *zOut++ = (u8)((c>>8)&0x00FF);
  1004   1005       }else{
  1005         -      if( c>=0xd800 && c<=0xdbff ) c = 0xfffd;
  1006   1006         *zOut++ = (u8)(((c>>10)&0x003F) + (((c-0x10000)>>10)&0x00C0));
  1007   1007         *zOut++ = (u8)(0x00D8 + (((c-0x10000)>>18)&0x03));
  1008   1008         *zOut++ = (u8)(c&0x00FF);
  1009   1009         *zOut++ = (u8)(0x00DC + ((c>>8)&0x03));
  1010   1010       }
  1011   1011     }
  1012   1012     sqlite3_result_text16le(context, (char*)z, (int)(zOut-z), sqlite3_free);