1
0
mirror of https://github.com/rfivet/uemacs.git synced 2024-06-13 06:50:41 +00:00

Assert that unicode are limited to 0-10FFFF.

This commit is contained in:
Renaud 2015-02-08 14:26:07 +08:00
parent 2cef071492
commit bdbd2d5437
3 changed files with 22 additions and 11 deletions

13
eval.c
View File

@ -523,10 +523,19 @@ static char *gtfun( char *fname) {
} }
break ; break ;
case UFCHR: case UFCHR: {
sz = unicode_to_utf8( atoi( argx), result) ; unicode_t c ;
c = atoi( argx) ;
if( c > 0x10FFFF)
retstr = errorm ;
else {
sz = unicode_to_utf8( c, result) ;
result[ sz] = 0 ; result[ sz] = 0 ;
retstr = result ; retstr = result ;
}
}
break ; break ;
case UFGTKEY: case UFGTKEY:
result[0] = tgetc(); result[0] = tgetc();

6
utf8.c
View File

@ -1,5 +1,7 @@
#include "utf8.h" #include "utf8.h"
#include <assert.h>
/* /*
* utf8_to_unicode() * utf8_to_unicode()
* *
@ -84,10 +86,10 @@ static void reverse_string(char *begin, char *end)
* possible sequence, while utf8_to_unicode() accepts both Latin1 and * possible sequence, while utf8_to_unicode() accepts both Latin1 and
* overlong utf-8 sequences. * overlong utf-8 sequences.
*/ */
unsigned unicode_to_utf8(unsigned int c, char *utf8) unsigned unicode_to_utf8( unicode_t c, char *utf8) {
{
int bytes = 1 ; int bytes = 1 ;
assert( c <= 0x10FFFF) ;
*utf8 = c ; *utf8 = c ;
if (c > 0x7f) { if (c > 0x7f) {
int prefix = 0x40; int prefix = 0x40;

2
utf8.h
View File

@ -5,6 +5,6 @@ typedef unsigned int unicode_t;
unsigned utf8_to_unicode( char *line, unsigned index, unsigned len, unsigned utf8_to_unicode( char *line, unsigned index, unsigned len,
unicode_t *res) ; unicode_t *res) ;
unsigned unicode_to_utf8( unsigned int c, char *utf8) ; unsigned unicode_to_utf8( unicode_t c, char *utf8) ;
#endif #endif